FakeClock
Defined in: fake-clock.ts:16
A Clock that only moves when told to, firing due timers in time order,
each with now() at its own time: the clock for testing code that schedules
work, without fake global timers.
Timers set while advancing are honoured in the same advance when due.
Example
Section titled “Example”const clock = new FakeClock(); clock.setTimer(100, () => console.log(clock.now())); // logs 100 clock.advance(250); clock.now(); // 250Implements
Section titled “Implements”Clock
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FakeClock(
start?):FakeClock
Defined in: fake-clock.ts:25
Parameters
Section titled “Parameters”start?
Section titled “start?”number = 0
The time to start at, 0 by default.
Returns
Section titled “Returns”FakeClock
Methods
Section titled “Methods”advance()
Section titled “advance()”advance(
milliseconds):void
Defined in: fake-clock.ts:41
Moves time forward by milliseconds, firing every timer due on the way.
Parameters
Section titled “Parameters”milliseconds
Section titled “milliseconds”number
Returns
Section titled “Returns”void
advanceTo()
Section titled “advanceTo()”advanceTo(
end):void
Defined in: fake-clock.ts:46
Moves time to end, firing every timer due on the way; never backwards.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
now():
number
Defined in: fake-clock.ts:29
The current time.
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”Clock.now
setTimer()
Section titled “setTimer()”setTimer(
at,callback): () =>void
Defined in: fake-clock.ts:33
Calls callback once at at, or as soon as possible when at is past.
Parameters
Section titled “Parameters”number
callback
Section titled “callback”() => void
Returns
Section titled “Returns”A function cancelling the timer; calling it after the timer fired does nothing.
() => void
Implementation of
Section titled “Implementation of”Clock.setTimer