Snapshot testing
Snapshot testing captures the serialised output of a function or component (rendered HTML, formatted JSON, computed data structure) and compares against a committed baseline on every run. Differences fail the test until the developer either fixes the code or accepts the new snapshot. Most associated with Jest, but supported broadly.
Snapshot testing is fast to write and excellent for catching unintended changes to structured output — a refactor that should be behaviour-preserving but accidentally changes rendered markup. The trade-off is signal quality: snapshots that frequently legitimately change train developers to accept-snapshot blindly, defeating the test's purpose. Healthy use: snapshot stable outputs (component renders, formatted reports), keep snapshots small (focused on one assertion), and review snapshot updates carefully in PRs. The anti-pattern is large monolithic snapshots updated on every PR without scrutiny.
Related terms
- Visual regression
Visual regression testing captures screenshots of UI components and compares them pixel-by-pixel (with tolerance) against baseline images on every change — catching unintended visual changes that escape unit and integration tests.
- Regression test
A regression test verifies that previously working functionality still works after a code change.
- Test fixture
A test fixture is the prepared state required to run a test — input data, mocked dependencies, configured environment, seeded database rows.