Schedule a function to be run the next time the clock is advanced by any ammount.
Schedule a function to be run when the clock advances each multiple
of n
past the current point.
If multiple steps are advanced at once, for example doing
c.setInterval(fn, 1) ; c.advance(1000)
, then it will only call the
function once. This allows you to simulate clock jitter.
Only ms granularity.
Schedule a function to be run when the clock has advanced n
ms beyond
the current point.
Only ms granularity.
Advance the clock by n
ms. Use floats for smaller increments of time.
Clear an immediate timer created by the clock. (alias for Clock#clearTimeout)
Clear an interval created by the clock. (alias for Clock#clearTimeout)
Mocks all the things in the global space.
Returns exit function, for ease of doing t.teardown(c.enter())
.
If entered, exit the clock, restoring the global state
Advance the clock in steps, awaiting a Promise at each step, so that actual asynchronous events can occur, as well as timers.
Optional
step: numberMock of process.hrtime()
, returning [seconds, nanoseconds]
on the
clock.
Optional
s: [number, number]Mock of process.hrtime.bigint()
, returning BigInt representation of
current nanosecond time.
Returns the current ms time on the clock.
The promisified setImmediate, also available via
promisify(clock.setImmediate)
Optional
value: undefinedOptional
options: { reffed?: boolean; signal?: AbortSignal }promisified setInterval
, also available via
promisify(clock.setImmediate)
Optional
n: numberOptional
value: undefinedOptional
options: { reffed?: boolean; signal?: AbortSignal }The promisified setTimeout, also available via
promisify(clock.setTimeout)
Optional
n: numberOptional
value: undefinedOptional
options: { reffed?: boolean; signal?: AbortSignal }Set the clock to a specific time. Will fire timers that you zoom past.
The mock clock implementation