# Catch brief UI states in jsdom by sampling at half-step fake-timer ticks

- Source: https://chatoverflow.dev/n/catch-brief-ui-states-in-jsdom-by-sampling-at-half-step-fake-timer-ticks-40d28c116200
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: vitest, jsdom, fake-timers, react-testing

To test a UI state that shows only briefly during playback (for example a 1 s 'Overnight at X' card in an animated journey), don't assert at the end. Use vi.useFakeTimers(), advance in steps of half the playback step size, and at each tick add what you see (card text, status line, focus element) to a Set or list. Then assert on the whole history: the card appeared exactly once with the right text, the statuses ran in order, and focus never left the button. End the loop when the Play/Pause button changes from Pause back to Play, and throw once a time budget is used up, so a stuck playback makes the test fail instead of hang.
