Skip to navigation

Claude Code Snapshot Review: Inspect the Diff, Not the Green

In short: Keep snapshots small and deterministic, review changed output line by line, and update only the intended cases.

Published 18 min read
On this page

Direct answer

Read the snapshot diff line by line before updating anything, and update only the named cases you have reviewed. Jest fails a snapshot test when rendered output differs from the stored snapshot, and a mismatch can be either an unintended regression or an intentional change. The test result tells you that output changed. It does not tell you which of those two things happened, and that judgment is the review.

A blanket update command makes failures disappear, which is exactly why it is dangerous. Run it and every delta in the file is accepted at once, including the ones nobody read. The alternative is to make the output deterministic, keep each snapshot small enough to read, update a single named case, and record what changed and why.

One Jest-specific behavior matters here. Jest documentation states that snapshots are not automatically written or updated in CI unless the update flag is explicitly passed. That is Jest behavior, and it should not be generalized to every runner. Your repository’s CI configuration decides what actually happens.

Why a green snapshot is not a reviewed snapshot

A snapshot test is a comparison against a stored artifact. The stored artifact was written by a previous run, and the previous run was not necessarily reviewed. When output changes, the test reports a difference. Deciding whether that difference is intended requires reading the new output and knowing what the feature is supposed to produce.

Skipping that reading has two failure modes, and both are quiet. The first is accepting a regression: a rendering bug, a missing field, a broken layout, recorded as the new expected output. The second is accepting noise: a timestamp, a generated identifier, or a randomized ordering baked into the artifact, which then fails on every future run until someone updates it again.

The cost shows up at review time. A pull request with a large generated diff gets skimmed, because the reviewer cannot tell signal from noise in a few hundred changed lines. The overengineering and large diffs guide describes the general review problem. Snapshots are the specific case where the diff is machine-generated and the reviewer is the only thing standing between a regression and a green build.

There is also an oracle problem. The previous snapshot is not a specification. It is a record of what the code produced before. Treating it as the product requirement inverts the relationship: the code defines the expectation, and the test can never fail for the right reason. The generated tests oracle bias guide covers that inversion in the testing context, and this post applies the same caution to stored output.

Evidence map from a snapshot diff to intended behavior, a dynamic field, and a review decision.
Editorial evidence map based on F013, F014, and F015. The update command records a decision; it does not make the decision for you.

Evidence and its limits

Official, F013: The Jest snapshot testing guide states that Jest fails a snapshot test when rendered output differs from the stored snapshot. The mismatch can be an unintended regression or an intentional change. Jest does not classify it for you.

Official, F014: The same guide documents property matchers for dynamic values and recommends deterministic output. Matchers can hide relevant changes when they are used too broadly, which is the tradeoff this post asks readers to manage rather than resolve.

Official, F015: Jest documentation states that snapshots are not automatically written or updated in CI unless the update flag is explicitly passed. This is Jest-specific. The Vitest snapshots guide describes a different runner, and neither document describes your CI configuration.

Official: Vitest snapshots cover the equivalent mechanism in Vitest. Vitest timers and Jest timer mocks cover the clock control that deterministic output depends on. Claude Code best practices supports a pass-or-fail check as the way to close a work loop.

No claim here treats a matching snapshot as correctness. No benchmark for review time, defect detection, or maintenance cost is cited.

Read the failure as a changed output

A failing snapshot is a message about output, and the useful first step is to read the diff as output rather than as a test result. The test is not broken. Something the code renders is different from what was recorded, and the diff shows exactly what.

Read it in three passes. The first pass asks what changed: which lines were added, removed, or altered. The second pass asks whether the change is a value change or a shape change, because a different timestamp and a missing element are different problems. The third pass asks which behavior produced it, which usually means opening the code that renders the snapshot and comparing it with the change in flight.

Snapshot delta What it suggests First question to ask
A timestamp or date shifted Uncontrolled clock Was this value meant to be fixed?
A generated ID changed Uncontrolled random source Is the ID part of the contract?
A list reordered Unspecified ordering Does the contract promise an order?
An element is missing Possible regression What code path produced the new output?
A value changed in one field Intended behavior change or a bug Which change was supposed to affect this?
Formatting or whitespace only Serializer change Is the format part of the interface?

The table is deliberately organized by delta shape rather than by feature. Most snapshot noise comes from a small number of uncontrolled inputs, and recognizing the shape tells you which control is missing before you touch the artifact.

The flaky tests triage guide covers the intermittent version of the same problem, where the uncontrolled input makes the test fail sometimes rather than always.

Check whether the change was intended

This is the step a blanket update skips. For each delta, decide whether the new output is what the feature should produce, and base that decision on the intended behavior rather than on the diff.

The question to answer is not “does the new output look reasonable”. It is “what behavior is this snapshot asserting, and is that behavior correct”. A snapshot that renders a checkout summary asserts the fields a customer sees, their order, and the computed total. A change to the total should trace to a pricing change. A change to the field order should trace to a design decision. A change that traces to neither is a regression regardless of how plausible it looks.

Snapshot delta Intended behavior Evidence to check Review decision
Discount line added Discount applies to eligible carts Pricing change and cart eligibility rule Update if the fixture is eligible
Currency symbol changed Locale-specific formatting Locale configuration for the test Update if the locale was intended
Empty state instead of results No-match state after filtering Whether the fixture returns zero matches Update only if zero matches is correct
Truncated description Length limit on display Whether the limit was specified Update if the limit is the contract
Missing button Regression in conditional rendering The condition that controls the button Reject the update and fix the code

The last row is the one that matters. A missing element is the delta most likely to be a real defect and the easiest to accept in a large diff. Treat any removal as a rejection candidate until someone explains it.

Workflow from reading a snapshot delta to checking intent, controlling dynamic fields, and updating only reviewed cases.
Editorial workflow based on F013, F014, and F015. Reading the delta against intended behavior is the step a blanket update command skips.

Control dynamic fields before updating

Updating a snapshot that contains an uncontrolled value just moves the problem to the next run. Control the value first, then update the artifact. Jest documents property matchers for dynamic values behind F014, and the guide recommends deterministic output, which is the direction to work in.

Three classes of dynamic value cover most cases. Clock values need a frozen or fake timer at the test boundary. Random values need a seed or an injected source. Environment values, such as locale, timezone, or a feature flag, need to be set explicitly for the test. The deterministic tests guide covers the clock and seed controls in detail, including the restoration step that keeps the control from leaking into the next test.

Dynamic field Matcher or fixed value Residual risk
Rendered timestamp Fixed date under fake timers Boundary at a date rollover not covered
Generated identifier Property matcher or injected source A wrongly formatted ID still matches
Relative time label Frozen clock at a known offset Boundary between label buckets untested
Locale-dependent format Explicit locale set for the test Other locales remain unverified
Random list order Sorted before comparison, or seeded Ordering contract left unasserted

The residual risk column is the honest part of the table. A matcher makes a test pass, and it also stops that portion of the output from being checked. A matcher applied to a whole object hides every change inside it. Apply matchers to the specific value that varies, and keep the rest of the output asserted.

Vitest’s and Jest’s timer controls are framework-specific. Do not assume one runner’s API applies to another, and check the installed version’s documentation before quoting an exact method name.

Keep snapshots focused and readable

A snapshot nobody can read is a snapshot nobody reviews, which returns the problem to the blanket update. Size is the control. A snapshot that renders an entire page produces a diff that spans several behaviors at once, and a reviewer faced with it will either approve blindly or ignore the file permanently.

Keep each snapshot asserting one thing. Split a page-level snapshot into component-level snapshots for the parts that matter, and use explicit assertions for the rest. A test that checks the total with an assertion and renders only the line items in a snapshot is easier to review than a test that snapshots the whole summary.

The same principle applies to serializing everything by default. Jest’s snapshot API reference describes the serialization mechanism. A snapshot of a large object graph records a lot and communicates little. Serializing the specific fields the feature depends on keeps the artifact legible and the diff meaningful.

Tradeoff between broad snapshots that catch more by accident and focused snapshots a reviewer can actually read.
Editorial tradeoff diagram based on F013 through F015. A broad snapshot catches more by accident and gets ignored on purpose; a focused snapshot is reviewable and states what it asserts.

Update only the named test cases

Update is a decision applied to a specific case. The command shape varies by runner and version, and the principle does not: name the test, review the delta, then update that one artifact.

# Update one named test after reading its diff
<runner> -t "checkout summary renders line items" -u

The interactive mode most runners provide is the better default for a single change, because it shows each delta and asks for a decision. A file-level or repository-level update flag is the wrong tool for a reviewed change, even when it is faster. Jest’s documented CI behavior behind F015, where snapshots are not updated in CI unless the flag is explicitly passed, exists precisely so that an update is a deliberate act rather than a side effect of a run.

Updated test Reviewed lines Reviewer Remaining question
Cart summary line items Added discount line Billing reviewer Rounding on multi-item carts
Invoice footer Changed total format Billing reviewer Locale coverage
Session header Removed retry hint Platform reviewer Whether the hint moved elsewhere

Record the remaining question in the change, not in memory. A reviewer who accepts a delta while noting an open question has done the review. A reviewer who accepts and moves on has not, and the open question becomes a defect discovered later.

Review the snapshot diff like code

A snapshot diff is a change to an assertion. Give it the same review a code change gets, because that is what it is. The reviewer is deciding whether the new expected output is correct, which is a stronger question than whether the test passes.

Review questions, in the order they pay off:

  1. Does each delta trace to an intended behavior change in this pull request?
  2. Is any delta a removal, and if so, what code path caused it?
  3. Did a dynamic value get a control before the artifact was updated?
  4. Is the snapshot still small enough that a future delta will be readable?
  5. Does any change weaken what the snapshot asserts, such as a broad new matcher?
  6. Is the update scoped to the named cases, or did it accept unrelated deltas?

A diff that fails the first question should be rejected, not updated. A diff that fails the fourth or fifth question has fixed this run and made the next one harder to review.

The verification guide develops the general review posture: ask what changed, what proves it, and what was not checked. For snapshots, the third question is where the honest answer usually is.

Control checklist covering delta intent, dynamic field control, focused snapshots, and named-case updates with review records.
Editorial control checklist derived from F013 through F015. Passing the checklist shows the update was reviewed; it does not prove the snapshot asserts the correct output.

Ask Claude Code to explain each delta

The agent can do useful work on both sides of a snapshot review. Before updating, ask it to explain what produced each delta by tracing the rendering code and the change in flight. That gives the reviewer a hypothesis to check rather than a diff to interpret alone.

After a decision, ask it to apply the update to the named case only, and to report the command it ran and the files it changed. The pass-or-fail loop described in the official best practices guidance fits this: a named test, a clear result, and a bounded change.

Two boundaries keep the agent from making the problem worse. It should not run a blanket update to make a failing test pass, because that accepts every unread delta at once. And an explanation of a delta is a hypothesis about the code, not evidence that the new output is correct. The debug log guide covers recording the prediction before the observation, which is what keeps an explanation from becoming an after-the-fact justification.

When the delta is caused by an uncontrolled input rather than a behavior change, the fix is the control described in the deterministic tests guide. When the snapshot is large enough that no delta is reviewable, the fix is to split it, and the complexity refactor guide covers the adjacent question of why the component grew in the first place.

Record unreviewed snapshot changes

A snapshot change that was not reviewed should be visible, not silent. The record is short: which snapshots changed, whether each was reviewed against an intended behavior, and what remains unreviewed. A change accepted without review is a decision to skip the review, and skipping is legitimate only when someone owns it.

The record also protects the next reviewer. A file with a history of unreviewed updates has a different trust level from one where every delta traces to a decision. The test selection guide makes the same move for skipped checks: record the boundary of the evidence rather than presenting a subset as the whole.

Treat a repeated pattern of unreviewed updates as a signal about the snapshots rather than about the reviewers. If a file is updated without review every sprint, the snapshots in it are probably too broad or contain uncontrolled values, and the fix is structural.

Recorded item Content Why it matters
Changed snapshots File and test name for each Names what was accepted
Review status Reviewed against intended behavior, or not Makes skipped reviews visible
Decision Update, reject, or split the snapshot Preserves the reasoning
Open question What the reviewer could not confirm Feeds the next review

Worked example: a checkout summary gains a discount line

Suppose a pricing change adds a discount line to a checkout summary, and the summary has a snapshot. The test fails. The diff shows one added line with the discount amount and one changed total.

The review traces both deltas to the intended behavior: eligible carts show a discount line, and the total reflects it. The fixture in the test represents an eligible cart, so the added line is correct. The changed total is the same change expressed in the total field. Both deltas are accepted, and the update is run against the named test.

A second snapshot in the same file also fails, because it renders a timestamp in the footer. The diff shows a different date. That delta does not trace to the pricing change, so the review rejects the update and adds a frozen clock instead. After the clock is controlled, the artifact matches the previous snapshot, and no update is needed.

Updated test Reviewed lines Reviewer Remaining question
Checkout summary with discount Added discount line, changed total Billing reviewer Rounding across mixed discounts
Checkout summary footer None; clock controlled instead Platform reviewer Date rollover boundary

The concrete win is that the pricing change is accepted with a named reviewer and a recorded open question, while an unrelated clock delta is rejected rather than baked in. The concrete loss is that the reviewed snapshot still only asserts what it renders: a field the summary does not display is not checked by this test at all.

Verdict that reviewing the delta against intended behavior keeps snapshots meaningful while a blanket update erases the signal.
Editorial verdict based on F013 through F015. Reading the delta is what makes the update a decision; a matching snapshot still does not prove correctness.

Snapshot review is one form of output review, and the neighboring guides cover the surrounding controls. Deterministic tests removes the clock and randomness that produce noise deltas. Flaky tests triage covers the intermittent version of the same failure. Selecting checks for changed code places snapshot tests in the run order.

For the assertion quality behind a snapshot, mutation testing shows which snapshots could not fail even when they ran. For a class of inputs rather than one rendered case, property tests cover stating an invariant and searching for a counterexample. For a boundary between two codebases, contract tests cover recording what a consumer relies on.

Evidence and review habits are covered by a debug log of facts and hypotheses and isolating shared fixture state. At the merge boundary, choosing a branch policy, defining merge checks, and recovering a failed merge group decide whether the review is enforced. For release traceability, atomic commits and commit messages that encode intent keep a snapshot update traceable to its reason, and deciding a version increment applies when the snapshot output is a consumer-facing contract. Quality work that keeps snapshot diffs small is covered by removing dead code with usage evidence, baselining static-analysis noise, and choosing reuse or independence.

Data gap and future update

No measured effect for snapshot review practice appears in the source set. No reduction in escaped regressions, review time, or maintenance cost is claimed, and no benchmark is cited. The mechanism rests on Jest’s documented mismatch behavior, matcher support, and CI update flag behavior, plus the equivalent Vitest snapshots documentation.

Runner behavior is version specific. The Jest CI behavior behind F015 is Jest-specific and must not be generalized, and the Vitest snapshot guide describes a different runner. A future update should add three things. Fresh content review of both runners’ snapshot documentation for current versions. A measured comparison of focused versus broad snapshots on review time and escaped defects. A documented pattern for migrating a suite from broad page-level snapshots to focused ones without losing existing coverage.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

For a separate OpenAI-format agent, One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. That is a different client and request format, not a workaround for Claude Code authentication. See the free model list and eligibility notes before choosing an agent route.

FAQ

Does a passing snapshot test prove the output is correct?

No. F013 describes a snapshot as a comparison against stored output, and a match only means the output did not change since the last recorded run. If the stored output was wrong, a passing test confirms the wrong output is stable.

Can I run one blanket update after a big refactor?

A blanket update accepts every delta at once, including regressions and noise. Review the diff first, control dynamic fields, and update the named cases you have read. Jest’s documented CI behavior behind F015 exists so that an update is explicit rather than automatic.

Why do my snapshots keep changing for no reason?

An uncontrolled value is reaching the output. The usual causes are the clock, a random source, or an environment value such as locale. Control the value with fake timers, a seed, or an explicit setting, then update the artifact. The deterministic tests guide covers the controls and their restoration steps.

Are Jest and Vitest snapshot behaviors the same?

No. Jest documents its own mismatch behavior, property matchers, and CI update flag. Vitest documents snapshots separately. Keep the runner named in each test and check the installed version’s documentation rather than assuming one runner’s behavior applies to another.

How large should a snapshot be?

Small enough that a future delta is readable in one screen. A snapshot asserting one behavior is reviewable. A snapshot of an entire page produces a diff that spans several behaviors, and a reviewer facing it will approve blindly or stop reading the file.

More Claude Code troubleshooting

Sources

More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
  • 100requests
    per day
  • 3Mtokens
    per day
  • 47free
    models
  • $0per
    token
  • No card
  • No end date
Claim $10 credit →