sinon-clock-singleton

2.0.1 • Public • Published

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.

/sinon-clock-singleton/

    Package Sidebar

    Install

    npm i sinon-clock-singleton

    Weekly Downloads

    2

    Version

    2.0.1

    License

    ISC

    Unpacked Size

    5.43 kB

    Total Files

    5

    Last publish

    Collaborators

    • eschwartz
    • four43
    • lhuffmam