我是jasmin / karma的新手,我正在尝试进行单元测试,但这会产生一些奇怪的行为:
测试:
it('should throw an error', () => {
const service: MyErrorHandler = TestBed.get(MyErrorHandler);
const errorFake = new HttpErrorResponse({
error: any,
headers: new HttpHeaders(),
status: 200,
statusText: 'MyErrorHandlerStatus',
url: undefined
});
service.handleError(errorFake, []).subscribe(x => expect(x).toEqual(errorFake));
});
输出:
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 0 of 43 SUCCESS (0 secs / 0 secs)
ERROR: 'A HTTP error has occurred: (params: [])', HttpErrorResponse{headers: HttpHeaders{normalizedNames: Map{}, lazyUpdate: null, headers: Map{}}, status: 200, statusText: 'Ok', url: null, ok: false, name: 'HttpErrorResponse', message: 'Http failure during parsin
g for (unknown url)', error: function(clazz) { ... }}
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 3 of 43 SUCCESS (0 secs / 0.344 secs)
ERROR: 'A HTTP error has occurred: (params: [])', HttpErrorResponse{headers: HttpHeaders{normalizedNames: Map{}, lazyUpdate: null, headers: Map{}}, status: 200, statusText: 'Ok', url: null, ok: false, name: 'HttpErrorResponse', message: 'Http failure during parsin
ERROR: 'ErrorHandlerCatchAll: An error has occurred: (params: [])', HttpErrorResponse{headers: HttpHeaders{normalizedNames: Map{}, lazyUpdate: null, headers: Map{}}, status: 200, statusText: 'Ok', url: null, ok: false, name: 'HttpErrorResponse', message: 'Http fai
lure during parsing for (unknown url)', error: function(clazz) { ... }}
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 3 of 43 SUCCESS (0 secs / 0.344 secs)
ERROR: 'ErrorHandlerCatchAll: An error has occurred: (params: [])', HttpErrorResponse{headers: HttpHeaders{normalizedNames: Map{}, lazyUpdate: null, headers: Map{}}, status: 200, statusText: 'Ok', url: null, ok: false, name: 'HttpErrorResponse', message: 'Http fai
Chrome 70.0.3538 (Windows 10 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\n[object ErrorEvent] thrown",
"str": "An error was thrown in afterAll\n[object ErrorEvent] thrown"
}
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 4 of 43 ERROR (0 secs / 0.364 secs)
Chrome 70.0.3538 (Windows 10 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\n[object ErrorEvent] thrown",
"str": "An error was thrown in afterAll\n[object ErrorEvent] thrown"
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 4 of 43 ERROR (0.407 secs / 0.364 secs)
Chrome 70.0.3538 (Windows 10 0.0.0) ERROR
Disconnected, because no message in 30000 ms.
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 4 of 43 DISCONNECTED (33.04 secs / 0.364 secs)
Chrome 70.0.3538 (Windows 10 0.0.0) ERROR
Chrome 70.0.3538 (Windows 10 0.0.0): Executed 4 of 43 DISCONNECTED (33.04 secs / 0.364 secs)
然后它挂了,我的电脑风扇开始旋转:)
其他测试包含使用错误服务的组件,我是否以某种方式锁定了它?
在这种情况下,由于缺少dep,在下面的输出中另一个测试失败了,但是当我注释掉我的测试并重新运行测试时,我似乎从来没有走得太远或看不到错误。在我们提供的一项活动服务上。
该测试在100%的时间内也运行良好,我做错了什么?任何帮助将不胜感激!