sinon-clock-singleton
v2.0.1
Published
Singleton wrapper around sinon.useFakeTimers()
Downloads
2
Readme
sinon-clock-singleton
A safer singleton wrapper around sinon.useFakeTimers()
Installation
Available on npm:
npm i --save-dev sinon-clock-singleton
Usage
const clock = require('sinon-clock-singleton');
// Creates a sinon Clock instance, and ticks forward 100ms
clock.tick(100);
// Restores the previous clock instance,
// and resets the current time to 25ms
clock.useFakeTimersSafe(25);
// Restores the system clock
clock.restore();
clock.useFakeTimersSafe()
By default sinon.useFakeTimers()
stubs out setImmediate
, which can wreack all sorts of havoc.
To avoid headaches, you can use clock.useFakeTimersSafe()
, which stubs out all methods except setImmediate
.
Usage in tests
If you're using a testing tool which supports afterEach
, the clock will automatically be restored after each test.