Socket
Socket
Sign inDemoInstall

@types/sinonjs__fake-timers

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/sinonjs__fake-timers

TypeScript definitions for @sinonjs/fake-timers


Version published
Weekly downloads
6.9M
decreased by-4.18%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @types/sinonjs__fake-timers?

@types/sinonjs__fake-timers provides TypeScript type definitions for the sinonjs/fake-timers library, which allows you to control the flow of time in your JavaScript code. This is particularly useful for testing code that relies on timers, such as setTimeout, setInterval, and Date.

What are @types/sinonjs__fake-timers's main functionalities?

Controlling setTimeout

This feature allows you to control the behavior of setTimeout, making it easier to test code that relies on delayed execution.

const sinon = require('sinon');
const clock = sinon.useFakeTimers();

setTimeout(() => {
  console.log('This will be printed after 2 seconds');
}, 2000);

clock.tick(2000); // Fast-forwards time by 2000ms

Controlling setInterval

This feature allows you to control the behavior of setInterval, making it easier to test code that relies on repeated execution.

const sinon = require('sinon');
const clock = sinon.useFakeTimers();

let count = 0;
const intervalId = setInterval(() => {
  count += 1;
  console.log('Interval count:', count);
}, 1000);

clock.tick(3000); // Fast-forwards time by 3000ms
clearInterval(intervalId);

Mocking Date

This feature allows you to mock the Date object, making it easier to test code that relies on the current date and time.

const sinon = require('sinon');
const clock = sinon.useFakeTimers(new Date(2020, 1, 1));

console.log(new Date()); // Outputs: 2020-02-01T00:00:00.000Z

clock.tick(86400000); // Fast-forwards time by 1 day
console.log(new Date()); // Outputs: 2020-02-02T00:00:00.000Z

Other packages similar to @types/sinonjs__fake-timers

Readme

Source

Installation

npm install --save @types/sinonjs__fake-timers

Summary

This package contains type definitions for @sinonjs/fake-timers (https://github.com/sinonjs/fake-timers).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sinonjs__fake-timers.

Additional Details

  • Last updated: Tue, 30 Nov 2021 01:31:09 GMT
  • Dependencies: none
  • Global values: none

Credits

These definitions were written by Wim Looman, Rogier Schouten, Yishai Zehavi, Remco Haszing, and Jaden Simon.

FAQs

Last updated on 30 Nov 2021

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