Skip to content
Latchkey

Jest "New snapshot was not written" (--ci flag) in CI

When Jest runs with --ci, it will not write new snapshots automatically. A test that has no committed snapshot fails instead of silently creating one, so missing snapshots cannot pass review unnoticed.

What this error means

A snapshot test fails with "New snapshot was not written: The update flag must be explicitly passed to write a new snapshot." The same test passes locally because local runs auto-create snapshots.

Jest output
● MyComponent › renders

    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 snapshot was never committed

The test creates a new snapshot, but the __snapshots__ file was not committed, so under --ci there is nothing to compare against and nothing is written.

CI runs Jest with --ci (often implicitly)

Jest treats a CI environment as --ci automatically, disabling snapshot creation so the run cannot pass by writing fresh snapshots.

How to fix it

Generate and commit the snapshot locally

  1. Run the test locally with the update flag to create the snapshot.
  2. Review the generated __snapshots__ file.
  3. Commit it so CI has a baseline to compare against.
Terminal
npx jest -u
git add **/__snapshots__/*.snap

Keep snapshot files in version control

Ensure .gitignore does not exclude __snapshots__, or CI will never see the committed baseline.

.gitignore
# .gitignore should NOT contain:
# __snapshots__/

How to prevent it

  • Commit snapshot files alongside the code that produces them.
  • Run jest -u and review diffs before pushing snapshot changes.
  • Do not gitignore the __snapshots__ directory.

Related guides

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