Skip to content
Latchkey

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.

Jest output
● <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.

Terminal
jest src/Badge.test.tsx        # creates __snapshots__/Badge.test.tsx.snap
git add src/__snapshots__/Badge.test.tsx.snap

Stop ignoring snapshot files

  1. Ensure __snapshots__/ and *.snap are NOT in .gitignore.
  2. Confirm the CI checkout includes the committed snapshots.
  3. Keep --ci on so an uncommitted snapshot is caught immediately, not silently written.

How to prevent it

  • Commit .snap files whenever you add a snapshot test.
  • Never gitignore __snapshots__.
  • Run CI with --ci so missing snapshots fail loudly.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →