intermediate
Arrange, Act, Assert and deterministic tests
Structure intent clearly, control time and randomness, isolate side effects, and make failures reproducible instead of intermittent.
Arrange-Act-Assert structures tests: setup data and dependencies, execute the behavior, assert outcomes—one logical act per test when possible. Deterministic tests produce the same result every run: control time with fake timers, fix random seeds, stub UUID generation, and avoid real network or race-prone sleeps.
Flaky tests erode trust—quarantine, fix root cause, or delete rather than retry indefinitely.
On interviews: diagnose a flaky test example (timing, shared state, or ordering) and show the AAA refactor.
Common pitfalls: multiple unrelated asserts masking failure cause, `setTimeout` without waiting strategy, and global mutable fixtures.
The trade-off is strict isolation versus realistic async—document why async waits exist.
Checklist:
- One clear Act block per test.
- Freeze time and randomness at boundaries.
- Reproduce flakes locally before merging retries.