Lolex

lolex

Fake "timers"

lolex useful for testing, extract from Sinon.JS helps to fake timer:

  • setTimeout
  • clearTimeout
  • setImmediate
  • clearImmediate
  • setInterval
  • clearInterval
  • requestAnimationFrame
  • cancelAnimationFrame
  • requestIdleCallback
  • cancelIdleCallback

Along with a clock instance that controls the flow of time. Lolex also provides a Date implementation that gets its time from the clock.

In addition in browser environment lolex provides a performance implementation that gets its time from the clock. In Node environments lolex provides a nextTick implementation that is synchronized with the clock - and a process.hrtime shim that works with the clock.

Get it: npm install lolex

Sample usage:

1
2
3
4
5
6
7
8
9
10
let lolex = require("lolex");
let clock = lolex.createClock();

clock.setTimeout(function () {
    console.log("nmotw.in");
}, 15);

// ...

clock.tick(15); // nmotw.in

GIF FTW!

lolex

Suggest a module

Comments