MockTimers

external interface MockTimers(source)

Mocking timers is a technique commonly used in software testing to simulate and control the behavior of timers, such as setInterval and setTimeout, without actually waiting for the specified time intervals.

The MockTimers API also allows for mocking of the Date constructor and setImmediate/clearImmediate functions.

The MockTracker provides a top-level timers export which is a MockTimers instance.

Since

v20.4.0

Functions

Link copied to clipboard
abstract external fun enable(options: MockTimersOptions = definedExternally)

Enables timer mocking for the specified timers.

Link copied to clipboard
abstract external fun reset()

This function restores the default behavior of all mocks that were previously created by this MockTimers instance and disassociates the mocks from the MockTracker instance.

Link copied to clipboard
abstract external fun runAll()

Triggers all pending mocked timers immediately. If the Date object is also mocked, it will also advance the Date object to the furthest timer's time.

Link copied to clipboard
abstract external fun setTime(milliseconds: Number)

Sets the current Unix timestamp that will be used as reference for any mocked Date objects.

Link copied to clipboard
abstract external fun tick(milliseconds: Number)

Advances time for all mocked timers.