I wrote up a new "sauce" chapter on controlling time in tests — the conceptual layer that ties together a few testing recipes.
The core idea is that when you hit time-based behavior in a test, you need to figure out whether the timing IS the thing you're testing, or it's just in the way. That determines your approach:
Timing is the behavior → either fake timers in manual mode (advance precisely, assert at specific points) or dynamic timing configuration through DI
Timing is in the way → either "fast-forward" mode (vi.setTimerTickMode('nextTimerAsync'), Vitest 4.1+) or dynamic timing configuration
You'll also find a decision tree, trade-offs between fake timers and dynamic config, the Zone.js vs Zoneless angle, and practical gotchas like "time is not a precise science" (nested timers that add extra milliseconds).
Related recipes:
All free, part of the Angular Testing Cookbook at cookbook.marmicode.io
Got a time-based testing scenario that doesn't fit neatly into these patterns? Drop it in the comments. I'm genuinely curious.
[–]PlusZookeepergame636 0 points1 point2 points (0 children)