-
Notifications
You must be signed in to change notification settings - Fork 42
Description
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.
