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.
● 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
- Run the test locally with the update flag to create the snapshot.
- Review the generated
__snapshots__file. - Commit it so CI has a baseline to compare against.
npx jest -u
git add **/__snapshots__/*.snapKeep snapshot files in version control
Ensure .gitignore does not exclude __snapshots__, or CI will never see the committed baseline.
# .gitignore should NOT contain:
# __snapshots__/How to prevent it
- Commit snapshot files alongside the code that produces them.
- Run
jest -uand review diffs before pushing snapshot changes. - Do not gitignore the
__snapshots__directory.