Socket
Socket
Sign inDemoInstall

jest-fake-timers

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-fake-timers

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


Version published
Weekly downloads
344
increased by2.08%
Maintainers
1
Install size
128 kB
Created
Weekly downloads
 

Readme

Source

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
  • tick(ms) Advances all scheduled tasks by given milliseconds. Updates Date.now() and performance.now() values.
  • restore() Clears all scheduled fale timers. Restores Date.now() and performance.now(). Restores real timers.
  • runAllTimers() Runs jest.runAllTimers()
  • runOnlyPendingTimers Runs jest.runOnlyPendingTimers()
  • runAllTicks Runs jest.runAllTicks()
  • runAllImmediates Runs jest.runAllImmediates()

FAQs

Last updated on 30 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc