Skip to content

Jest Inline Snapshot Not Updating Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Jest Inline Snapshot Not Updating Fix. We cover key concepts, practical examples, and best practices.

Your toMatchInlineSnapshot() test fails and the snapshot value in the test file doesn't update automatically — you get a snapshot mismatch without an inline update.

The Problem

// WRONG — empty inline snapshot
test('renders greeting', () => {
  expect('Hello, World!').toMatchInlineSnapshot();
  // Jest will fail here — no snapshot to compare against
});
Snapshot: "Hello, World!" does not match stored inline snapshot ""

Jest needs a snapshot string inside toMatchInlineSnapshot() to compare against. An empty call means there's no stored snapshot.

Step-by-Step Fix

1. Let Jest write the snapshot

// RIGHT — first run will fail, then Jest inserts the value
test('renders greeting', () => {
  expect('Hello, World!').toMatchInlineSnapshot();
});

Run with --updateSnapshot:

npx jest --updateSnapshot

After update, the file becomes:

// RIGHT — Jest wrote the snapshot inline
test('renders greeting', () => {
  expect('Hello, World!').toMatchInlineSnapshot(`"Hello, World!"`);
});

2. Write the snapshot manually

// RIGHT — manual inline snapshot
test('renders greeting', () => {
  expect('Hello, World!').toMatchInlineSnapshot(`"Hello, World!"`);
});

3. Use inline snapshots with objects

// RIGHT — inline object snapshot
test('user object', () => {
  expect({ id: 1, name: 'Alice' }).toMatchInlineSnapshot(`
{
  "id": 1,
  "name": "Alice",
}
`);
});

4. Update inline snapshots in watch mode

npx jest --watch
# Press 'u' to update all snapshots
# Press 'i' to update individually

Expected output:

PASS  tests/inline.test.js
  ✓ renders greeting (4 ms)
  ✓ user object (3 ms)

Prevention Tips

  • Run --updateSnapshot when adding new inline snapshots
  • Use backtick strings for multi-line inline snapshots
  • Keep inline snapshots small and readable
  • Review inline snapshot changes in PR diffs
  • Consider file snapshots for large component trees

Common Mistakes with snapshot inline

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world JEST code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my inline snapshot not update when I run tests?

Jest doesn't update snapshots by default — it only compares. Use --updateSnapshot flag or press u in watch mode. Inline snapshots are written directly into the source file, so Jest modifies your test file.

Can I use property matchers with inline snapshots?

Yes. Pass an object with asymmetric matchers as the first argument: expect(container).toMatchInlineSnapshot({ id: expect.any(Number) }, \...`)`. The matchers apply before snapshot comparison.

Are inline snapshots better than file snapshots?

Inline snapshots are better for small, focused assertions because the expected value is visible in the test file. File snapshots are better for large component output or when you want to keep test files clean.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro