即使抛出错误,Jasmine toThrow也不起作用
Jasmine toThrow does not work even though an error is thrown
即使抛出错误,该代码也会失败。
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();
相关文章:
- 使用jasmine模拟对服务器的调用
- 为什么jasmine期望不验证是否抛出了错误
- 模拟chrome.storage.local函数使用Jasmine
- 函数在promise被解析后被调用,但Jasmine未通过测试.为什么?
- 为什么spyOn"停止函数“”的所有执行;Jasmine(要求澄清Jasmine 2.2间谍文件)
- 可以't在Jasmine中调用Javascript函数
- Jasmine单元测试在监视服务方法时失败
- 如何使用Jasmine测试Knockout.js点击绑定
- 如何在jasmine测试中为有角度的项目注入依赖项
- 仅首先需要使用jasmine从节点添加一个文件
- 使用Jasmine捕获传递给不同JavaScript文件中函数的参数
- 什么'与Jasmine相比,使用Sinon.js的优势是什么;内置于间谍
- 测试iFrame的位置.href是在jasmine单元测试中设置的
- 在Karma Jasmine单元测试用例中检查日期格式
- Jasmine:测试setTimeout函数会抛出一个错误
- Jasmine,Angular;rootScope$广播“;测验
- JavaScript 代码没有通过 Jasmine toThrow 测试
- Jasmine 的 toThrow 匹配器是否需要将参数包装在匿名函数中?
- angular resource promise catch, jasmine toThrow()
- 即使抛出错误,Jasmine toThrow也不起作用