Skip to main content

externalClock

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

externalconstructor

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

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

      Returns Clock

    Methods

    externaltoJSON

    • toJSON(): JSONObject
    • Returns JSONObject

    externalsetAhead

    • 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

    externaltick

    • 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>

    externalnow

    externalwaitFor

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


      Parameters

      Returns Promise<void>