Last active
October 28, 2016 03:21
-
-
Save wujiang/d51acc3c3ecd03ad2108f4ce3a1b1ca3 to your computer and use it in GitHub Desktop.
mocha-3.1.2 fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
describe('timer test', function() { | |
it('should not report done() called multiple times', function(done) { | |
async.waterfall([ | |
(next) => { | |
var timer = setTimeout(() => { | |
next(null, 'timer1'); | |
}, 2); | |
// a mock function to run for 1 millisecond | |
setTimeout(() => { | |
clearTimeout(timer); | |
next(null, 'main 1'); | |
}, 1); | |
}, | |
(msg, next) => { | |
console.log(msg); | |
var timer = setTimeout(() => { | |
next(null, 'timer2'); | |
}, 2); | |
setTimeout(() => { | |
clearTimeout(timer); | |
next(null, 'main 2'); | |
}, 1); | |
} | |
], function(err, msg) { | |
done(); | |
console.log(msg); | |
}); | |
}); | |
}); |
Author
wujiang
commented
Oct 27, 2016
•
working version:
var async = require('async');
describe('timer test', function() {
it('should not report done() called multiple times', function(done) {
async.waterfall([
(next) => {
var needClear = true;
var timer = setTimeout(() => {
needClear = false;
next(null, 'timer1');
}, 2);
// a mock function to run for 1 second
setTimeout(() => {
if (needClear) {
clearTimeout(timer);
next(null, 'main 1');
}
}, 1);
},
(msg, next) => {
console.log(msg);
var needClear = true;
var timer = setTimeout(() => {
needClear = false;
next(null, 'timer2');
}, 2);
setTimeout(() => {
if (needClear) {
clearTimeout(timer);
next(null, 'main 2');
}
}, 1);
}
], function(err, msg) {
done();
console.log(msg);
});
});
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment