One hour in milliseconds
One minute in milliseconds
One second in milliseconds
One week in milliseconds
Sets up fake timers and Date implementation within your Jest test file. You should call this at the top of the file (not within a test or an after/before); tests that need fake timers should go into their own test file.
Returns an object containing a setTime
function which you can use to set
the current (fake) date within your test to a particular JavaScript
timestamp (number of milliseconds since 1970-01-01T00:00:00Z).
Enables the jest.useFakeTimers()
integration, and overwrites global.Date
with a custom function that automatically applies your test file's given
offset.
Returns the real-world current timestamp (unaffected by fake timers).
Sets the offset
such that a call to Date.now()
(or new Date()
) would
return this timestamp if called immediately (but time continues to
progress as expected after this). Also advances the timers by the
difference from the previous offset
, if positive. Setting time backwards
is allowed (like setting back the system clock on a computer), but will
not advance (or undo the advancement of) any timers.
Since advancing the time a few hours might not run all the intermediary code quite right, we actually step it up by a configurable increment (defaults to one minute) at a time. Setting time backwards (no matter how far back) is done all at once.
the target timestamp
the maximum we should advance time by at once in order to step towards timestamp
Wait a number of milliseconds of real time (not mocked time); useful for allowing the runloop or external systems to advance.
Polls until the condition passes.
Polls the condition
callback every pollInterval
ms of real time. If/when
it returns a truthy value, resolves successfully. If maxDuration
is
exceeded before condition()
returns true, rejects with an error.
a callback function that should return true when no more sleep is required
an optional maximum duration to sleep
an optional period of how long we should wait between checks; lower values increase load on the server but may make tests pass faster, larger values are more efficient but increase test latency.
Generated using TypeDoc
One day in milliseconds