This package has been deprecated

Author message:

Deprecated in favour of Jest 26+ modern fake timers implementation

jest-fake-timers
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

jest-fake-timers

jest-fake-timers is a sinon-alike wrapper around jest built-in fake timers, which adds mocking capability for Date.now() and performance.now()

Usage

import { useFakeTimers } from "jest-fake-timers";

// init fake timers with 10000 for Date.now() and 500 for performance.now()
const clock = useFakeTimers(10000, 500);

setTimeout(() => {
    console.log(`Date: ${Date.now()}`);
    console.log(`Performance: ${performance.now()}`);
}, 10000);
clock.tick(10000);
// Date: 20000
// Performance: 10500

// reset fake timers and restore real ones
clock.restore();

Methods

  • useFakeTimers(date, perf) Enables jest fake timers, mocks Date.now() and performance.now() with passed values. Returns instance of FakeTimer class.

FakeTimer

Readme

Keywords

none

Package Sidebar

Install

npm i jest-fake-timers

Weekly Downloads

168

Version

1.0.2

License

MIT

Unpacked Size

131 kB

Total Files

8

Last publish

Collaborators

  • atsikov