Skip to main content

Clock

A Clock tells the time. This abstraction allows Serenity/JS to have a single place in the framework responsible for telling the time, and one that can be easily mocked for internal testing.

const now: Timestamp = new Clock().now()

Learn more

Index

Constructors

constructor

  • new Clock(checkTime?: () => Date): Clock
  • Parameters

    • checkTime: () => Date = ...

    Returns Clock

Methods

setAhead

  • Sets the clock ahead to force early resolution of promises returned by Clock.waitFor.

    Useful for test purposes to avoid unnecessary delays.


    Parameters

    Returns void

tick

  • tick(): Promise<void>
  • Returns a Promise that resolves after one tick of the clock.

    Useful for test purposes to avoid unnecessary delays.


    Returns Promise<void>

now

waitFor

  • waitFor(duration: Duration): Promise<void>
  • Returns a Promise that will be resolved after the given duration


    Parameters

    Returns Promise<void>