Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@types/sinonjs__fake-timers
Advanced tools
TypeScript definitions for @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.
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
Jest is a JavaScript testing framework that comes with built-in utilities for mocking timers. It provides similar functionalities to @types/sinonjs__fake-timers, such as jest.useFakeTimers() and jest.advanceTimersByTime(). Jest is more comprehensive as it includes a full testing framework along with timer mocks.
Lolex is a standalone library for creating fake timers, similar to sinonjs/fake-timers. It allows you to control the flow of time in your tests. Lolex is often used as a dependency in other testing libraries, including Sinon itself.
npm install --save @types/sinonjs__fake-timers
This package contains type definitions for @sinonjs/fake-timers (https://github.com/sinonjs/fake-timers).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sinonjs__fake-timers.
These definitions were written by Wim Looman, Rogier Schouten, Yishai Zehavi, Remco Haszing, and Jaden Simon.
FAQs
TypeScript definitions for @sinonjs/fake-timers
The npm package @types/sinonjs__fake-timers receives a total of 5,904,015 weekly downloads. As such, @types/sinonjs__fake-timers popularity was classified as popular.
We found that @types/sinonjs__fake-timers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.