-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async.waterfall is not working with Sinon.JS fake timers in Node.js #106
Comments
var async = require("async");
var sinon = require("sinon");
var clock = sinon.useFakeTimers();
async.auto({
"f2": ["f1", function f2(cb) {
console.log("fn2");
cb();
}],
"f1": function f1(cb) {
console.log("fn1");
setTimeout(function(){
cb();
}, 100);
}
});
clock.tick(1000); |
I found the source of the issue and a way to "patch" async so it works nicely with Sinon.JS: if (typeof sinon === "object" && typeof sinon.timers === "object") {
(function(){
var nextTick = async.nextTick;
async.nextTick = function(fn) {
if (global.setTimeout === sinon.timers.setTimeout)
nextTick(fn);
else
global.setTimeout(fn, 0);
};
})();
} |
You're not crazy. We had to do something similar when using fake timers, too. |
If you only need to fake the date you can do |
Using
async.series
, the following example works just fine.But if we change
async.series
byasync.waterfall
, the program exits beforefn2
is called.UPDATE: In the browser,
async.waterfall
works fine.The text was updated successfully, but these errors were encountered: