@sinonjs/fake-timers
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@sinonjs/commons | 3.0.1 | 10.39 kB | BSD-3-Clause | prod |
@sinonjs/fake-timers
is a JavaScript implementation of the timer APIs. It includes setTimeout
, clearTimeout
, setImmediate
, clearImmediate
, setInterval
, clearInterval
, requestAnimationFrame
, cancelAnimationFrame
, requestIdleCallback
, cancelIdleCallback
, along with a clock instance that controls the flow of time. The package also provides a Date
implementation that gets its time from the clock. It is perfect for situations where you need the semantics of time scheduling, especially in automated tests, but don't want to actually wait. By using this package, you can simulate the passage of time.
Here's an example illustrating how you use @sinonjs/fake-timers
:
// Require the package
var FakeTimers = require("@sinonjs/fake-timers");
// Create a new clock
var clock = FakeTimers.createClock();
// Schedule a function on the clock
clock.setTimeout(function () {
console.log("Function executed after 15 ms");
}, 15);
// Advance the clock
clock.tick(15);
In this example, we first require the @sinonjs/fake-timers
package. We then create a new clock and schedule a function to run after 15 milliseconds. Finally, we advance the clock by 15 milliseconds, leading to the execution of the function.
Regarding the @sinonjs/fake-timers
documentation, you will find a comprehensive API reference directly within the package's README file on the Github repository available at https://github.com/sinonjs/fake-timers. This documentation includes details on how to create a clock, schedule events on it, and control the flow of time. You'll also find information on the various methods available and how to use them.