Injected timers
Injected timers are timer functions supplied to a utility instead of being accessed directly from the global environment. Passing setTimeout and clearTimeout as dependencies allows tests to use fake timers and control when callbacks execute.
Minimal example
type Timers = {
setTimeout(fn: () => void, ms: number): unknown;
clearTimeout(id: unknown): void;
};Learn this concept
Lesson 4.19 · Resilient client patternsUsed in exercises
Exercise 4.22 · Restaurant search utilitiesRelatedJitter