mock timers and timeouts so you can test timer dependent modules without waiting and realistically.
var timers = require('mocktimers')
var time = timers();
console.log(time.now() == Date.now())// true
time.timeout(function(){
console.log(time.now()-1000 >= Date.now()) // true
},1000);
timeouts are executed in order
var time = require('mocktimers')()
var s = "";
time.timeout(funciton(){
s += 'c'
console.log('i know my ',s); // prints "i know my abc"
},1000)
time.timeout(function(){
s += 'a'
time.timeout(function(){
s += 'b'
},10)
},10)
the default export is a function that returns an object with all of the timing methods. "time"
setTimeout. returns id
setInterval. returns id
stop a timeout or interval by id
corrected Date.now
return an object with this interface that uses the real time functions
so to use this in your tests you would have to use an object like this in your program instead of hitting setTimeout directly. and maybe hang it off of module.exports so you can patch it from the test with this object.
var time = {interval:setInterval,timeout:setTimeout,now:Date.now,clear:clearTimeout};
time.unmock has been added to help with this.