Documentation Home
This page is for an older version of Jasmine (3.1).
The current stable version of Jasmine is: 5.4. You can also look at the docs for the next release: Edge

Class: Clock

Clock()

Jasmine's mock clock is used when testing time dependent code.

Constructor

new Clock()

Note: Do not construct this directly, Jasmine will make one during booting. You can get the current clock with jasmine.clock.

Methods

install() → {Clock}

Install the mock clock over the built-in methods.

Returns:
Type
Clock

mockDate(initialDateopt)

Instruct the installed Clock to also mock the date returned by new Date()

Parameters:
Name Type Attributes Default Description
initialDate Date <optional>
now

The Date to provide.

tick(millis)

Tick the Clock forward, running any enqueued timeouts along the way

Parameters:
Name Type Description
millis int

The number of milliseconds to tick.

uninstall()

Uninstall the mock clock, returning the built-in methods to their places.

withMock(Function)

Execute a function with a mocked Clock

The clock will be installed before the function is called and uninstalled in a finally after the function completes.

Parameters:
Name Type Description
Function closure

The function to be called.