How to write a jasmine test case for the next class with a constructor that has a dependency on http
import {Injectable} from 'angular2/core'; import {Http, HTTP_PROVIDERS} from 'angular2/http'; @Injectable() export class MockUserService { items:Array<any>; constructor(http:Http){ http.get('http://127.0.0.1:8080/src/data/names.json') .subscribe(res => { this.items = res; console.log('results found'); }) } }
I tried as follows:
it('Testing user login', inject([MockUserService,Http], (mockUserService:MockUserService ) => { let http:Http; let mockUserService: MockUserService = new MockUserService(http); expect(1+1).toEqual(2); }); );
I get a DI error: DI error image
angular jasmine karma-jasmine
vi fi
source share