snapshot-testing

Installation
SKILL.md

Snapshot Testing

Concept of the skill

Snapshot testing is a tactical testing technique in which the output of a system under test is captured on a known-good run, stored as an artifact (the snapshot), and compared against fresh output on each subsequent test run. A mismatch is the test failure. The snapshot itself is the assertion — there is no hand-written claim about what the output should be; the claim is "the output should equal what it was last time, until someone deliberately approves a new baseline." Five primitives: (1) target output — data structure / DOM tree / image / text; (2) snapshot artifact — stored serialized, checked into version control (or stored in a centralized service for visual snapshots); (3) comparison and diff — line-by-line text diff for data/DOM/text; perceptual diff with tolerance threshold for images; (4) approval cycle — the discipline-critical primitive: when a test fails, read the diff, decide whether the change was intentional, and either update the baseline (intentional) or fix the production code (unintentional); (5) stability discipline — timestamps, random IDs, iteration order, environment values must be normalized before capture or the test churns on noise.

Replaces hand-specifying every part of a complex output (impractical for large rendered DOM trees, JSON API responses, generated SQL, full-page visual layouts) with capture-and-compare. Solves the problem that some outputs are structurally complex enough that writing explicit assertions is prohibitively expensive — a rendered component might have hundreds of nodes; a JSON response might have dozens of fields; a generated migration might have many lines — and that small structural drift should be visible to a reviewer's eye. The technique's value is in surfacing every subsequent change to a reviewer's eye so that intentional changes are approved and unintentional changes are caught as regressions. Sub-purposes: (1) characterize legacy code as a safety net before refactoring (Feathers' original use); (2) catch visual regressions on UI components (Chromatic, Percy, Storybook); (3) detect structural drift in API responses or generated outputs over time. The technique fits where the output is structurally complex, where small drift should be visible, and where the team will honor the approval cycle.

Distinct from testing-strategy, which owns the strategic question of what to test at which level — this skill owns one tactical technique within that strategy. Distinct from property-based-testing, which asserts universal claims about output structure — snapshot captures a specific output and asserts equality to a baseline; the two complement (PBT for universal contracts; snapshots for complex structural outputs easier to capture than specify). Distinct from test-driven-development, which prescribes writing the test before the code — snapshot testing requires the code to exist before the snapshot can be captured; fits poorly with strict TDD on greenfield code, well with characterization of existing code. Distinct from code-review, which owns the broader review discipline — the approval cycle of snapshot testing is operationally part of the review process code-review owns; the diff must be small, legible, and actually read. Distinct from e2e-test-design — e2e covers user-journey testing; visual snapshots compose inside e2e tests as a regression net for UI changes the journey assertions don't catch. Distinct from example tests — use precise hand-written assertions for simple outputs; snapshots are wasteful for primitive return values and inappropriate for behavioral contracts that need explicit specification. A snapshot test is to a piece of output what a wedding photograph is to a memory of the day — the photograph does not say what the wedding should have looked like, only what it did look like; on the next anniversary, you compare the room to the photograph and notice 'the curtains are different' (intentional — they were replaced) or 'the picture is crooked' (unintentional — fix it). A photograph filed away without anyone ever looking at it again is not a record; it is paper. A snapshot file the team auto-accepts via -u is the same. The wrong mental model is that snapshot testing is "automatic regression coverage" and that running jest -u to update snapshots in response to failures is part of the workflow. It is not — auto-updating without review removes the testing value. The discipline is the approval cycle: when a snapshot test fails, the developer must read the diff, decide whether the change was intentional, and either approve (update the baseline) or fix the production code. A team that types jest -u reflexively has automated the maintenance and removed the verification. Adjacent misconceptions: that snapshot testing is a substitute for behavioral specification (it is not — it captures what the output was, not what it should be; pair with example tests for behaviors that need explicit specification); that snapshots can be arbitrarily large (they cannot — diffs must be readable by humans; snapshots over a few hundred lines should be split or replaced with per-property assertions); that snapshots on output with timestamps, random IDs, or iteration-order-dependent collections work (they do not — the test will churn on noise and train the team to ignore failures; normalize unstable sources before capture: freeze time, seed ID generators, sort collections, pin locale); that visual snapshots should use bit-for-bit equality (they should not — perceptual diff with a tuned tolerance threshold ignores rendering noise while catching real changes); that snapshot diffs in PR review are reviewed automatically (they are not — reviewers must actually read them, and visual snapshot services like Chromatic/Percy provide review UI for exactly that purpose); and that snapshot testing fits everywhere (it does not — fits well for complex rendered DOM, large JSON responses, generated code, visual regression; fits poorly for simple return values, behavioral contracts needing explicit specification, and any unstable output the team will neither stabilize nor stop using).

Coverage

The tactical testing technique in which the output of a system under test is captured on a known-good run, stored as an artifact, and compared against fresh output on each subsequent test run. Covers the five primitives (target output, snapshot artifact, comparison and diff, approval cycle, stability discipline), the taxonomy across output target (data / DOM / image / text), storage location (inline / file / centralized service), approval process (auto-update / manual edit / PR-integrated review), comparison strategy (exact / perceptual / structural / property-equality), and scope (unit / integration / full-page visual). Covers the Feathers characterization-test pattern as a legitimate use, and the auto-update-without-review anti-pattern as the technique's most common failure mode.

Philosophy of the skill

A snapshot test is a photograph of the output. The photograph itself is not a specification — it doesn't say what the output should be, only what it was on the day of capture. The technique's value is in surfacing every subsequent change to a reviewer's eye, so that intentional changes are approved and unintentional changes are caught as regressions.

The discipline is the approval cycle. When a snapshot test fails, the developer reads the diff, decides whether the change was intentional, and either updates the baseline (intentional) or fixes the production code (unintentional). A team that types jest -u reflexively in response to every failing snapshot has automated the maintenance and removed the verification.

Snapshot testing fits where the output is structurally complex enough that hand-specifying every part is expensive, where small drift should be visible, and where the team will honor the approval cycle. It fits poorly where the output is simple (use precise assertions), unstable (the snapshot will churn), or where the team treats failures as nuisances to silence rather than signals to read.

Installs
3
First Seen
May 18, 2026
snapshot-testing — jacob-balslev/skills