Jest "New snapshot was not written" - --ci Blocks Snapshot Creation
A test calls toMatchSnapshot() but no stored snapshot exists, and Jest is running with --ci. Unlike a local run - which would create the snapshot and pass - --ci refuses to write a new snapshot and fails instead.
What this error means
CI fails with "New snapshot was not written: The update flag must be explicitly passed to write a new snapshot." It passes locally (where the snapshot is auto-created) but fails in CI because the .snap was never committed.
● <Badge /> › matches snapshot
New snapshot was not written: The update flag must be explicitly
passed to write a new snapshot.
This is likely because this test is run in a continuous integration
(CI) environment in which snapshots are not written by default.Common causes
A new snapshot test never committed its .snap
The test was added and passed locally (Jest auto-wrote the snapshot), but the generated .snap file was not committed, so CI has nothing to compare against.
Snapshot files gitignored or cleaned
If __snapshots__ is gitignored or wiped before the run, every snapshot looks new, and --ci refuses to write all of them.
How to fix it
Generate and commit the snapshot
Run the test locally to create the snapshot, then commit the .snap file alongside the test.
jest src/Badge.test.tsx # creates __snapshots__/Badge.test.tsx.snap
git add src/__snapshots__/Badge.test.tsx.snapStop ignoring snapshot files
- Ensure
__snapshots__/and*.snapare NOT in.gitignore. - Confirm the CI checkout includes the committed snapshots.
- Keep
--cion so an uncommitted snapshot is caught immediately, not silently written.
How to prevent it
- Commit
.snapfiles whenever you add a snapshot test. - Never gitignore
__snapshots__. - Run CI with
--ciso missing snapshots fail loudly.