Fake timers are paired with explicit clock control
Why it matters
Calling vi.useFakeTimers() or jest.useFakeTimers() freezes the JavaScript clock at the moment of the call. Any code that depends on setTimeout, setInterval, or Date.now() then hangs indefinitely — the timer callback never fires because the clock never advances. Tests that use useFakeTimers without a corresponding vi.advanceTimersByTime() or vi.runAllTimers() will either timeout or silently pass without actually executing the time-dependent code path. ISO-25010:2011 testability requires that all branches of code under test are actually exercised.
Severity rationale
Low because frozen-timer tests typically don't produce false passes — they usually hang or time out — but they do silently skip the time-dependent code branch.
Remediation
Always pair vi.useFakeTimers() with an explicit clock advancement, and restore real timers after the test. The test cannot verify timer-dependent behavior unless the clock is manually advanced:
it('debounces rapid input', () => {
vi.useFakeTimers()
const callback = vi.fn()
const debounced = debounce(callback, 100)
debounced()
debounced()
debounced()
vi.advanceTimersByTime(100) // fires the debounced callback
expect(callback).toHaveBeenCalledTimes(1)
vi.useRealTimers()
})
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Test Reality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · maintainability.testability — Testability (maintainability sub-characteristic)
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-slop-test-theater·automated