mocha.js - Mocha 重试不适用于 should.js 进行异步调用
问题描述
我正在尝试使用 mocha retry 进行异步测试,但它似乎不起作用。当测试失败时(在回调的上下文中)它不会调用 done() ,因此重试不起作用。
我已经用这种方式编写了很多测试,我需要一个不需要更改所有测试流程的解决方案
var should = require('should');
var counter = 0;
describe('async',function(){
it('AsyncTest', function(done) {
setTimeout(function()
{
console.log('attempt::', counter++);
counter.should.equal(3);
done();
}, 300);
});
});
以下简单代码正在同步测试中工作:
var counter = 0;
var should = require('should');
describe('sync', function() {
it('sync', function() {
if(counter > 1) {
console.log('counter::', counter);
} else {
counter++;
counter.should.equal(10);
}
});
});
运行异步代码结果: mocha testRetries.js --timeout 259200000 --ui bdd --retries 3
异步尝试:: 0 1) AsyncTest
0 通过 (319ms) 1 失败
1)异步异步测试:
Uncaught AssertionError: expected 1 to be 3
+ expected - actual
-1
+3
at Assertion.fail (/Users/shaylang/dev/nodejsautomation/src/node_modules/should/cjs/should.js:258:17)
at Assertion.value (/Users/shaylang/dev/nodejsautomation/src/node_modules/should/cjs/should.js:335:19)
at Timeout._onTimeout (testRetries.js:20:27)
运行同步代码结果:
mocha testRetries.js --timeout 259200000 --ui bdd --retries 3
同步计数器:: 2 ✓ 同步
1 次通过(8 毫秒)
摩卡——版本 6.1.4
解决方案
推荐阅读
- java - 在静态方法中使用 @Autowired HttpServletRequest 请求对象
- python - Pandas str.split() 在 for 循环中不起作用(jupyter)
- javascript - 使用 React Router 从 Expressr 下载文件
- java - android的清单文件发生了什么?
- haskell - 在 Haskell 中将原始二进制文件写入文件?
- android - 底部元素使用 AppBarLayout 在导航栏后面绘制元素
- python-3.x - Panda lambda TypeError object float no len()
- objective-c - [__NSArrayM addObjectsFromArray:]:消息发送到已释放实例 0x283e8c990 - Apprtc
- javascript - 为什么我的日期增加 2 天而我只给出值 1
- ios - 类型“ChatViewController”没有成员“showOrHideKeyboard”