Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

atsikov/jest-fake-timers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[DEPRECATED] jest-fake-timers

This is a deprecated package, as with modern fake timers jest does a perfect job on mocking Dates

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

About

sinon-alike wrapper for jest.useFakeTimers() which adds Date.now() and performane.now() mocking

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published