Skip to content

Snapshot Mismatch

Error message

                Snapshot does not match — run with --updateSnapshot to update
              

Quick summary

The output of your code changed since the snapshot was last saved. This could be an intentional change or a bug — you need to review the diff.

Why this happens

  • You intentionally changed the code's output (e.g., updated a component's markup).

  • A bug caused unexpected output changes.

  • A dependency update changed the output format.

  • The snapshot was corrupted or manually edited incorrectly.

Minimal example

✗ Broken code
// Component changed but snapshot not updated
test('renders', () => {
  expect(render(<Button label="New" />)).toMatchSnapshot();
  // Fails: snapshot has label="Old"
});
✓ Fixed code
// Review the diff, then update if intentional
// npx jest --updateSnapshot
// Or fix the component if the change is a bug

Review the diff first. If the change is correct, update the snapshot. If not, fix the code.

How to diagnose

  • Read the diff in the error output — it shows what changed between the snapshot and current output.

  • Determine if the change is intentional (update the snapshot) or a bug (fix the code).

  • Check recent code changes that might have affected the output.

How to fix

  • If intentional: run jest --updateSnapshot (or jest -u) to save the new snapshot.

  • If it's a bug: fix the code so the output matches the saved snapshot.

  • Review the updated snapshot file before committing to ensure the changes are correct.

How to prevent

  • Always review snapshot diffs before updating — never blindly run --updateSnapshot.

  • Use --ci flag in CI to prevent accidental snapshot updates.

  • Commit snapshot files to version control and review them in code reviews.

Related Resources

Related Glossary

Related Lessons

← Back to language