Should I test that?

Are snapshot tests worth it?

Verdict

Yes

Snapshot tests are worth it in small numbers: keep one short snapshot per UI component for the text users read, review every snapshot diff like code, and check behaviour with explicit assertions.

Why

Snapshot tests are worth it in small numbers, reviewed like code. For a Jest or Vitest snapshot of a React component, Blast radius is users, because a missing button reaches customers, and Change frequency is regularly, since product teams change a component's markup about once a month. Detectability is same-day, because a visible break draws a user report within a day, and Reversibility is trivial, because a revert removes it and no data stays behind. Test cost is moderate: the snapshot takes a minute to write, but every markup change fails it and someone must read the diff. Rule R12 gives Test minimally. The case is borderline: with Test cost heavy, the decision is Do not test.

When the decision changes
WhenDecisionWhy
The snapshot covers a whole page whose markup changes in most weeksDo not keep the page snapshot; rely on explicit assertions for the elements users needChange frequency rises to constantly and Test cost to heavy: a snapshot of several hundred lines fails on every markup change
The snapshot pins a welcome email that goes to every new customerTest: snapshot each rendered email template and read every diff in reviewReversibility rises to impossible and Detectability moves to eventually: a sent email cannot be taken back, and nobody on the team reads it
The snapshot pins output that another program reads, such as generated code or a config fileTest: keep the full output as a golden-file snapshot and review each diffDetectability moves to eventually and Reversibility rises to with-effort: a changed format looks fine to a person and breaks the tools that parse it
The component shows a price or an order totalTest mandatory: assert the exact amount explicitly, because a snapshot records whatever amount the code producedBlast radius rises to money and Reversibility to costly: customers buy at the price on the screen, and the shop honours it or refunds
A shared design-system button appears on dozens of screensTest minimally: one short snapshot of the default variant of the buttonChange frequency falls to rarely and Detectability moves to eventually: a change shows on screens its author never opened, so the decision holds

What breaks if you don't test

An accidental markup change ships when no test looks at the changed element. A refactor of a shared EmptyState component drops its action button, and the team settings page loses its "Invite member" button. A customer reports it the next morning, and a revert fixes it within the hour.

What you lose if you over-test

Large snapshots fail on changes nobody cares about: a renamed CSS class, an extra wrapper div, a hashed class name from a CSS-in-JS library. When a design change fails every snapshot that renders a shared button, the developer runs jest -u and the reviewer scrolls past the .snap files. From then on the suite stays green whatever the markup does, and the team believes the UI is covered.

How to test

Test each component at the unit level with Jest or Vitest and Testing Library: one short snapshot of the text users read, plus explicit assertions for behaviour. A role query such as getByRole('button', { name: 'Export CSV' }) fails with a message that names the missing button. Prefer toMatchInlineSnapshot, which keeps the expected value in the test file. The no-large-snapshots rule of eslint-plugin-jest rejects snapshots longer than 50 lines by default. Commit snapshot files and review them as code, as the Jest snapshot guide asks; on CI, Jest fails a test whose snapshot is missing instead of writing one.

When the answer changes

  • Snapshot updates pass review in a minute, which shows that nobody reads the diffs.
  • The output leaves the screen: an email goes to customers, or another program parses the text.
  • The component starts to show prices.

Real incident + Code example

The export button that jest -u removed

On a reporting dashboard I worked on, every page had a full-page snapshot. A toolbar refactor put the Export button behind a new canExport prop that the report page did not pass. The report page snapshot failed along with 38 others that had changed on purpose. The developer ran jest -u, the reviewer approved about 1,200 changed snapshot lines, and a customer asked the next morning where CSV export had gone. We replaced the page snapshots with tests of this shape:

// Before: the whole page in a .snap file, accepted with jest -u
test('renders the report page', () => {
  const { container } = render(<ReportPage report={report} />);
  expect(container).toMatchSnapshot();
});

// After: an explicit assertion for what users need
test('offers CSV export', () => {
  render(<ReportPage report={report} />);
  expect(screen.getByRole('button', { name: 'Export CSV' })).toBeEnabled();
});

// ...and one short inline snapshot that a reviewer reads in the diff
test('shows the report period', () => {
  render(<ReportPage report={report} />);
  expect(screen.getByRole('heading', { level: 2 }).textContent)
    .toMatchInlineSnapshot(`"March 2026, all regions"`);
});

Without the button, offers CSV export fails with a message that names it.

FAQ

Is snapshot testing worth it?

Snapshot testing is worth it for short snapshots of output that people or programs read, not for whole pages, which fail on every markup change until the team accepts updates unread. A short snapshot takes a minute to write, and a reviewer reads its whole diff.

When should I use snapshot testing?

Use snapshot testing when the whole output is the thing to check: generated code, command-line output, a rendered email, or a short piece of UI text. Use an explicit assertion when one value matters, such as a price or an enabled button.

Should I use snapshot tests or explicit assertions?

Use explicit assertions for behaviour and for any value with one right answer, such as an amount or an accessible name. Use a short snapshot for output where any change deserves a look.

Should I snapshot test React components?

Yes, a React component earns one short snapshot of the text users read, next to Testing Library assertions for its behaviour. Do not snapshot a deep component tree, because it fails on every markup change and gets updated without review.