http.get
呼び出しを実際の応答で単体テストできますが、応答を嘲笑することはできませんか?動的応答でhttp.get呼び出しをユニット単位でテストする
...
export class CarService{
...
getCars():Observable<any>{
return this.http.get("http://someurl/cars").map(res => res.json());
}
...
}
ユニットテスト:
it('retrieves all the cars', injectAsync([CarService], (carService) => {
return carService.getCars().toPromise().then((result) => {
expect(result.length).toBeGreaterThan(0);
});
}));
それはhttp.get
コールを実行し、それが数秒間一時停止すると、それは以下のエラーが返されます:単位で
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.