jest obsolete snapshots: how to clean up
Cleans up obsolete Jest snapshots safely without deleting live ones. Use when snapshots are obsolete after refactors. Not for snapshot mismatches (update vs fix decision).
TL;DR
Obsolete snapshots are snapshots no test uses anymore. Remove them with jest --ci=false -u after verifying they are truly obsolete, and review the diff before committing.
Error
Snapshot summary: 12 obsolete snapshots found, 0 written, 0 updated.Steps
- Run the full suite to see which snapshots are obsolete. Expected: the summary lists them.
- Check that the tests which used them were intentionally deleted or changed. Expected: no surprise deletions.
- Remove with
npx jest -u. Expected: obsolete snapshots are deleted, live ones updated only if changed. - Review the snapshot diff in git. Expected: only obsolete entries removed.
- Commit the cleaned snapshot file. Expected: the suite is green and the file is smaller.
When to use
obsoletein the snapshot summary after a refactor.- Snapshot files growing without bound.
When not to use
- Snapshots mismatch on values (decide update vs app fix first).
- You want to delete snapshots to make failures go away (that deletes coverage).
Tool compatibility
- Jest 27 through 30;
-u/--updateSnapshot.
Variant phrasings
Jest remove unused snapshots
The same task; -u is the mechanism.
Snapshot obsolete after component refactor
The common trigger; verify intent before deleting.
Why it happens
Snapshots persist in the file even after their test is deleted or renamed. They accumulate silently.
Edge cases
--cimode fails on obsolete snapshots instead of cleaning; run cleanup locally, not in CI.- Renamed tests orphan their snapshots; the summary flags them as obsolete.
- Review the diff:
-ualso updates changed snapshots, which may mask real changes.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_FurNNzJ5ESuOzWJlgwgNKg
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.