我正在使用业力和茉莉花。下面是我要使用spyOn测试的功能。
getCaSyncStatus() {
service.getBenefitsCaSyncStatus()
.pipe(
catchError((err : HttpErrorResponse) => {
return throwError(err);
})
)
.subscribe(res => {
}, err => {
if(err && (err.status === 503 || err.status === 0)) {
this.toaster.pop('error', 'API is not available');
this.someValue = 'xxx';
} else if(err.status === 500 ) {
this.toaster.pop('error', 'API is not available, Contact Support');
this.msg = 'API is down';
}
else {
this.someValue = 'yyy';
}
});
}
所以如果我这样用spyOn
抛出状态代码
spyOn(dashboardService, "getBenefitsCaSyncStatus").and.returnValue(Observable.throw({ status: 500 }));
component.getCaSyncStatus();
fixture.detectChanges();
tick();
它引发错误“没有初始化烤面包机容器以接收烤面包”。尽管我的根组件中有<toaster-container></toaster-container>
。