Jasmine可以用来测试并发失败吗?
Can Jasmine be made to test for concurrency failures?
我怀疑基于其他响应(如Jasmine:测试setTimeout函数抛出错误和如何测试具有Jasmine setTimeout的函数?),这里没有好的解决方案,但我想弄清楚如何更好地处理下面的第二个测试:
describe('Tests', function () {
it('succeed', function () { expect(true).toBeTruthy(); });
it('have problems', function(done) {
setTimeout(function() { console.log(undefined.foo); });
setTimeout(done, 5);
});
it('fail', function() { fail; });
it('also fail', function() { fail; });
});
Jasmine当前的行为是运行第一个测试,然后在第二个测试中遇到导致异常的setTimeout时退出;最后两个失败的规范永远不会运行。
当然,我的用例不是这样的!异步错误发生在调用堆栈的某个地方,越过河流,穿过树林。这显然是一个错误,它发生了,没有被捕获!但是不幸的是,如果这样的错误总是终止Jasmine本身,而不是导致测试用例失败。我相信你想要try...catch
或承诺与Jasmine的done.fail()
。
承诺:
it('gets some huge file', done => {
getFile('http://movies.com/holymountain.mp4')
.then(res => {
expect(res.status).toBe(200)
done()
})
.catch(done.fail)
})
Try/catch
it('gets some huge file', done => {
try {
getFile('http://movies.com/holymountain.mp4')
expect(getFile.status).toBe(200)
done()
} catch (e) {
// console.log(e) // ???
done.fail()
}
})
参考问题
相关文章:
- 当json解析空响应时,Whatwg-Fetch失败,我该如何防止它
- JsFiddle在分叉后描述失败
- 为什么不'当单元测试出现解析错误时,我的因果报应测试会失败
- 当一些承诺失败时,如何继续使用$q.all()
- 失败:等待Protractor与页面同步时出错:“”;在窗口上找不到角度”;
- 在Jquery中单击传播失败
- 网页上失败的javascript会导致所有其他脚本失败
- 带有对象解析的响应javascript ajax失败
- 一台特定计算机的Ajax请求数据未定义/失败
- Nodejs服务器:加载资源失败:服务器的响应状态为404(未找到)
- jQuery.getJSON失败,语法错误
- ng disabled在放入多个表达式时失败
- Jasmine单元测试在监视服务方法时失败
- jQuery分页下一页和上一页按钮在点击零或超过最后一页后失败
- 在iframe的情况下,jQuery html()将失败
- 在我的情况下,使用带有变量失败的 jquery 选择器
- CSS中的转换似乎失败了,原因是什么
- Mozilla Builder 编辑器取消转义 Unicode 字符,并发 w. AMO 上传失败
- Jasmine可以用来测试并发失败吗?
- jQuery在并发ajax请求/then/失败时:哪个请求失败