[英]How can I cover unit test case for eventEmitter object exists in abstract class (jasmine / Angular8)
[英]How to cover IF/ELSE condition with Angular 4 Jasmine unit test case
您可以使用MockBackend參考來模擬http響應: https ://angular.io/api/http/testing/MockBackend
您可以輕松定義自己的響應並測試所有是否
// before each test
beforeEach(() => {
this.injector = ReflectiveInjector.resolveAndCreate([
{provide: ConnectionBackend, useClass: MockBackend},
{provide: RequestOptions, useClass: BaseRequestOptions},
Http,
// other dependencies like Router / AppConfig
]);
this.authenticationService = this.injector.get(AuthenticationService);
this.backend = this.injector.get(ConnectionBackend) as MockBackend;
this.backend.connections.subscribe((connection: any) => this.lastConnection = connection);
});
// in your test
const mockErrorResponse = {status: 200};
this.lastConnection.mockRespond(new Response(new ResponseOptions({body: JSON.stringify(mockErrorResponse)})));
tick();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.