#2075·jasmine

jasmine clock: a way to run to the last timer

Author: atscottCreated Sep 6, 2025Updated Sep 12, 2026
Labelsfeature request

Feature Proposal

Add a clock feature to either get the time until the last timer (preferred?) or tick to the last timer.

Context

Angular's fakeAsync functionality has a feature that runs all current timers: flush

Teams may be looking for replacements to this functionality to get rid of the ZoneJS dependency.

Sinon mock clock has a feature to run to the last timer, which is a good replacement: runToLastAsync

Both jest and vitest expose this functionality as well (since their clock implementations are backed by sinon)

I don't know of a feature in jasmine that does something similar

Since jasmine doesn't have direct tickAsync variants, I would propose a feature to get the time until the last timer (e.g. clock().timeUntilLast()) This allows developers to choose either the sync or async version (indirectly with autoTick)

Beyond just the fact that the API exists in two other popular mock clocks, when/why is it useful? When tests don’t use mock clocks, they can wait for things, either awaiting the promise returned by an api (e.g await router.navigate(…)) or by polling for an expected state. When a mock clock is installed, this isn’t possible (unless the mock clock also automatically advances) since time needs to be ticked manually forward. Test authors often don’t know or care the exact amount of time to tick time forward and only want to flush any outstanding or pending work (e.g. router.navigate(…); flush();) then write the test assertions on the final state.

Example

javascript
jasmine.clock().tick(jasmine.clock().timeUntilLast());

// or

jasmine.clock().autoTick();
...
await new Promise(r => setTimeout(r, jasmine.clock().timeUntilLast());

Other Information

No response