【发布时间】:2020-01-22 20:52:42
【问题描述】:
我开始尝试 jasmine,我想使用 toThrowError() 函数,但我的测试不想成功。
我有一个函数会抛出错误:
test.service.ts
test(list:{}){
if(list == null){
throw new TypeError();
}
else{
// do something...
}
}
还有我的测试:
it('shall throw an error', inject()
[
TestService
],
(
testService: TestService
) => {
let test = testService.test(null);
expect(test).toThrowError(TypeError);
}
);
我的测试失败并出现 Uncaught TypeError(当我调用它时,我是在 try catch 中进行的)。
【问题讨论】:
标签: angular typescript jasmine