【发布时间】:2018-08-16 18:38:18
【问题描述】:
我正在为一个函数编写一个测试,并且必须触发该函数的 .catch 部分,但 Jasmine 的间谍由于某种原因不能这样做。 待测方法:
foo(){
doStuff()
.catch((error) => {
//stuff I still have to test
bar()
})
}
doStuff() 返回一个 Promise(因此是 .catch-Setup),但对于这个测试,它应该会抛出一个错误。
这是我的测试:
it('tests the error handling of foo',(done) =>{
spyOn(object,'foo').and.throwError('Test Error');
object.foo();
expect(object.bar).toHaveBeenCalled();
done();
});
我处理这个问题的方式是错误的吗?这是茉莉花的错误吗? (谷歌没有找到任何东西) [我坚持(完成)设置,因为几乎所有其他测试都是异步的,我想保持这种风格]
[我无法更改要测试的代码]
【问题讨论】:
标签: javascript testing jasmine throw