即使抛出错误,此代码也会失败。
it('should throw error when foo config value is falsey', (done) => {
const config = { foo: null, bar: 'some-name' };
expect(quux.withConfig(config).load('*', (err, inst) => { done(); })).toThrow();
});
我也尝试过这个
it('should throw error when foo config value is falsey', (done) => {
const config = { foo: null, bar: 'some-name' };
expect(SelfServiceCompletedJobStore.withConfig(config).load('*', (err, inst) => { })).toThrow();
done();
});
错误消息:
should throw error when foo config value is falsey
- Error: Requires a non-empty foo:String
最佳答案
你应该将一个函数传递给expect(...)。代码如下:
expect(quux.withConfig(config).load('*', (err, inst) => { done(); })).toThrow();
实际上正在尝试将调用结果传递给expect(...),
改用匿名函数:
expect(function(){
quux.withConfig(config).load('*', (err, inst) => { done(); });
}).toThrow();
关于javascript - 即使抛出错误,Jasmine toThrow 也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39377523/