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

ts
type Timers = {
  setTimeout(fn: () => void, ms: number): unknown;
  clearTimeout(id: unknown): void;
};

Learn this concept

Lesson 4.19 · Resilient client patterns

Used in exercises

Exercise 4.22 · Restaurant search utilities
Prerequisite conceptsInjected clockDebounce
RelatedJitter