Mocha测试套件因未捕获的异常而暂停
Mocha test suite halted on uncaught exception
我无法阻止未捕获异步异常停止一组mocha测试。看起来它应该只通过测试,但摩卡进程退出了。对于给定的测试用例:
describe('AsyncWow', () => {
it('should proceeed after this test', (done) => {
setTimeout(() => {
throw new Error('boom');
done();
});
});
it('but never gets here', (done) => {
done();
});
});
产生终端输出:
AsyncWow
/source/test/foo.test.js:6
throw new Error('boom');
^
Error: boom
at [object Object]._onTimeout (/source/test/foo.test.js:6:16)
at Timer.listOnTimeout (timers.js:110:15)
它正在停止,因为done()
从未被调用(就像发生错误后一样,它搜索异常处理程序,下一行从未被调用),
我会把代码改成…
describe('AsyncWow', () => {
it('should proceeed after this test', (done) => {
setTimeout(() => {
try{
throw new Error('boom');
done(new Error('This line should not be reached.'));
}catch(e){
done();
}
});
});
it('but never gets here', (done) => {
done();
});
});
或者如果你想让错误通过测试。。。
describe('AsyncWow', () => {
it('should proceeed after this test', (done) => {
setTimeout(() => {
try{
throw new Error('boom');
done();
}catch(e){
done(e);
}
});
});
it('but never gets here', (done) => {
done();
});
});
相关文章:
- 如何临时暂停浏览器渲染,然后恢复整个页面
- jQuery循环在特定位置暂停
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- 最小化时暂停Javascript动画
- jQuery:暂停按钮可以暂停所有其他操作
- tiltSlider播放/暂停视频元素(如果li有当前类)
- Canvas+svg路径动画,在路径中的特定点暂停一段时间,然后继续
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- CSS动画暂停并使用javascript播放
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- 如何暂停和恢复jquery间隔
- 为什么浏览器没有为语法错误抛出异常
- java,javascript签名的小程序(文件选择,ftp上传)安全性/套接字异常
- node.js和express中的异常处理
- 派生进程的stdout在管道传输时工作异常
- NodeJS和pg promise,捕获PostgreSQL异常
- Mocha测试套件因未捕获的异常而暂停
- Jquery 函数创建一个异常的暂停
- 如何解决“;从本机“异常触发恢复/暂停事件”;Cordova安卓系统
- 如何使ie Javascript调试器在捕获异常时也暂停?