Jest Obsolete Snapshots / "--ci" Won't Write New Snapshots
In --ci mode Jest refuses to write snapshots. A snapshot that was never committed fails (instead of being created as it would locally), and snapshots no longer referenced are reported as obsolete.
What this error means
CI reports "New snapshot was not written. The update flag must be explicitly passed..." for a missing snapshot, or "N obsolete snapshots found." Locally the same run passes because Jest auto-writes there.
› 1 snapshot written. <-- locally
# in CI (--ci):
New snapshot was not written. The update flag must be explicitly passed
to write a new snapshot.
› 1 snapshot not written.Common causes
Snapshot never committed
The .snap file was created locally but not committed. Locally Jest writes it and passes; with --ci (or CI=true) it fails instead of writing.
Obsolete snapshots left behind
A renamed or deleted test leaves stale entries in the .snap file. With --ci Jest will not prune them and flags them as obsolete.
How to fix it
Generate and commit snapshots locally
jest -u # write/update snapshots locally
git add **/*.snap # commit them so CI has themPrune obsolete snapshots
- Run
jest --ci=false -ulocally to remove obsolete entries. - Confirm renamed tests no longer reference old snapshot names.
- Keep
--ciin CI so missing snapshots fail loudly instead of being written.
How to prevent it
- Commit
.snapfiles and review their diffs in PRs. - Run CI with
--ciso missing snapshots fail rather than write. - Periodically prune obsolete snapshots locally.