2.0.1 • Published 4 years ago

sinon-clock-singleton v2.0.1

Weekly downloads
31
License
ISC
Repository
github
Last release
4 years ago

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.

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

8 years ago

1.0.0

8 years ago