Giter Site home page Giter Site logo

elecash / angular2-testing Goto Github PK

View Code? Open in Web Editor NEW
98.0 98.0 43.0 18 KB

Angular 2 testing tutorial with Karma and Jasmine

Home Page: http://twofuckingdevelopers.com/2016/01/testing-angular-2-with-karma-and-jasmine/

License: MIT License

HTML 5.88% JavaScript 29.34% TypeScript 64.79%

angular2-testing's People

Contributors

0x-r4bbit avatar babylonzeus avatar elecash avatar koyner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

angular2-testing's Issues

npm run build throws error

I am facing below issue on execution of npm run build

C:\Users\khushboo-singh\Downloads\angular2-testing-master>npm build run
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x8
6)\nodejs\node_modules\npm\bin\npm-cli.js" "build" "run"
npm ERR! node v6.3.0
npm ERR! npm v3.10.3
npm ERR! path C:\Users\khushboo-singh\Downloads\angular2-testing-master\run\pack
age.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\khushboo-singh
\Downloads\angular2-testing-master\run\package.json'
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\khushboo-singh
\Downloads\angular2-testing-master\run\package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\khushboo-singh\Downloads\angular2-testing-master\npm-debug
.log

Source code not running

Hello,

I've been trying to implement the configuration presented in the associated tutorial, and upon failing I resorted to test first using the present source code. However, after downloading the source code and running the npm commands, I ran it and got the errors visible in the attached log file.
Basically those are the same errors I get in my own project after I implemented the described solution, I would greatly appreciate if the author can take a look at this log file.

npm-debug.log.txt

spec.ts for http get service is not working.

Following is my 'user.service.ts' file which uses http get to receive data from users.json file :

import {Injectable} from '@angular/core';
import { IUser } from './userInterface';
import { Http, Response } from '@angular/http';
import{ Observable } from 'rxjs/Observable';
@Injectable()

export class UserService {
private _productUrl = '../app/users/users.json';
constructor(private _http: Http) {}
getUsers(): Observable {
return this._http.get(this._productUrl)
.map((response: Response) => response.json());
}
}

I have following 'user.service.spec.ts' file to test the above service :

import {
describe,
expect,
beforeEach,
it,
inject,
beforeEachProviders
} from '@angular/core/testing';
import { UserService } from './user.service';
import { HTTP_PROVIDERS } from '@angular/http';

export function main() {

describe('UserService test', () => {
let service: UserService;

//setup
beforeEachProviders(() => {
return[
HTTP_PROVIDERS,
//provide(XHRBackend, {useClass: MockBackend}),
UserService
];
});

beforeEach(inject([UserService], (l:any) => {
service = l;
}));

it('should return the list of users', () => {
service.getUsers().subscribe(x => {
expect(x).toEqual(jasmine.any(Array));
});
});
});
}

Any guess why this is not working and throws error (attached screenshot) when I run 'npm test'... Thanks in advance.
untitled

npm run build fails

Hello,
I'm getting below error when I try to do npm run build, I have updated node version v7.0.0
Failed at the [email protected] pretest script 'npm run build'

Please share your thought.

Thank you
Manu

Expand the example with an Http dependant service

There seems to be a total lack of (working) examples on the internet on how to test a service which depends on Http. Since I guess 90% of the services depend on it, it would be a bit more of a real world example.

It would be awesome if it could be added to this repository, and the article on the website.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.