elecash / angular2-testing Goto Github PK
View Code? Open in Web Editor NEWAngular 2 testing tutorial with Karma and Jasmine
Home Page: http://twofuckingdevelopers.com/2016/01/testing-angular-2-with-karma-and-jasmine/
License: MIT License
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
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
When running npm 'test' command on windows OS, i get an error saying
'Rm is not recognized as an internal or external command'.
Installing npm package rimraf globally and then changing 'rm' to 'rimraf', did the trick.
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.
Some code couldn't work smoothly now. Please update the code if u have time slot.
I got an error: Error: XHR error (404 Not Found) loading http://localhost:9876/angular2/src/core/dom/browser_adapter.
The solution was to change karma-test-shim.js line 31
*from * System.import('angular2/src/core/dom/browser_adapter')
*to * System.import('angular2/src/platform/browser/browser_adapter')
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.
If yes then how.
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.