sinon-clock-singleton
A safer singleton wrapper around sinon.useFakeTimers()
Installation
Available on npm:
npm i --save-dev sinon-clock-singleton
Usage
const clock = ; // Creates a sinon Clock instance, and ticks forward 100msclock; // Restores the previous clock instance,// and resets the current time to 25msclock; // Restores the system clockclock;
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.