What Is Snapshot Testing?

Snapshot testing captures a component's rendered output (or any serializable value) and compares future test runs against that saved snapshot, flagging any u...

Published November 15, 2026

Snapshot testing saves the output of a function or component the first time, then compares future runs to that stored snapshot and fails if it changes. It catches unintended changes cheaply.

The concept

On the first run the test writes a snapshot file. Later runs compare; if the difference is intentional you update the snapshot, otherwise you found a regression.

Best for stable, small outputs (serialised data, error messages, small components). Large snapshots become noise that people approve without reading.

Compare with stored output

  1. First run: output is saved to __snapshots__
  2. Next run: output is compared
  3. Same → pass
  4. Different → fail, review: bug or intended update?

Practical examples

Jest

test('formats user', () => {
  expect(formatUser({ name: 'Ada', age: 36 })).toMatchSnapshot()
})

Inline snapshot

expect(format(1234.5)).toMatchInlineSnapshot(`"1,234.50"`)

Update after an intended change

npx jest -u

Common mistakes

  • Huge snapshots nobody reviews.
  • Blindly running -u.
  • Snapshotting volatile data like dates or ids.

Key takeaways

  • Compare output to a stored baseline.
  • Keep snapshots small.
  • Review changes before updating.

FAQ

Are snapshots committed?

Yes, they belong in version control.

Snapshot vs assertion?

Assertions state exact expectations; snapshots detect any change.

More General articles