Vitest snapshot mismatch with updates disabled in CI
When Vitest detects CI, it disables snapshot writing. A new snapshot is not created and an outdated one is not updated, so toMatchSnapshot fails rather than silently passing by rewriting the file.
What this error means
A snapshot assertion fails in CI with a diff, or with a note that new snapshots are not written in CI. The same test passes locally because local runs create or update snapshots automatically.
❯ src/Card.test.tsx > renders
Error: Snapshot `renders 1` mismatched
- Expected
+ Received
(new snapshots are not written automatically in CI)Common causes
A snapshot was never committed
The test produces a snapshot that exists locally but was not committed, so CI has no baseline and refuses to write one.
Output drifted from the committed snapshot
Rendered output changed but the snapshot was not updated, and CI mode will not rewrite it, so the diff fails the test.
How to fix it
Update and commit snapshots locally
- Run Vitest with
-uto refresh snapshots. - Review the diff to confirm the change is intended.
- Commit the updated snapshot files.
npx vitest run -u
git add **/__snapshots__/*.snapKeep snapshot files tracked
Make sure snapshot directories are not gitignored so CI sees the committed baseline.
# .gitignore should NOT contain:
# __snapshots__/How to prevent it
- Commit snapshots together with the code that produces them.
- Review snapshot diffs before pushing.
- Do not gitignore
__snapshots__.