Skip to content

commandTesting

Update Snapshots Safely

Reviews every changed snapshot before updating it and flags the ones that hide a real regression.

npx workspacetemplates add update-snapshots-safely --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/update-snapshots-safely.md14 lines · 1.2 KBFile
---
description: Reviews every changed snapshot before updating it and flags the ones that hide a real regression.
argument-hint: "[test file or name pattern]"
---

Review snapshot changes safely. Scope: $ARGUMENTS (all failing snapshot tests if empty).

1. Run the tests without any update flag and list each failing snapshot with its test name and file. Check `git status` for snapshot files that already changed.
2. For every failure, show the diff in a compact form and classify it: **intended** (matches the code change you can see in `git diff`), **cosmetic** (whitespace, ordering, generated class names), or **suspicious** (removed content, empty output, error text, undefined or NaN, changed behavior with no matching source change).
3. Explain each suspicious case, find the cause in the source and propose a fix. Do not update those snapshots.
4. Update only the intended and cosmetic ones, one file at a time, using the runner's targeted option (for example `jest -u path -t "name"` or `vitest -u path`), never a blanket update.
5. Rerun the whole suite.

Report counts for intended, cosmetic and suspicious, what was updated, and what remains. Ask before committing.

What it does

Running the update flag on a red suite is how bugs get approved. This command shows each snapshot difference, decides whether it is an intended change, and updates only the ones that are.

Suspicious differences, such as a missing field or an error message captured as expected output, are held back and explained.

Example

you › /update-snapshots-safely src/components

agent › 14 snapshot failures: 9 intended (new aria-label), 3 cosmetic (class order), 2 suspicious.
Suspicious: Table.test shows an empty body, the rows prop is no longer passed after the refactor.
Updated 12, held 2. Fix the Table regression?

Questions

Why not just run the update flag?
A blanket update records whatever the code now produces, including bugs. Reviewing first keeps snapshots meaningful.
Does it work outside JavaScript?
Yes. The method fits any snapshot or golden-file tool; it adapts the commands to your runner.
  • Add Edge Case Tests

    CommandTesting

    Free
  • Add Regression Test

    CommandTesting

    Free
  • Coverage Gaps

    CommandTesting

    Free
  • E2E Scenario

    CommandTesting

    Free