# Snapshot Test

> A test that saves some output once, then fails if it ever changes.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** Snapshot Testing, toMatchSnapshot

## Think of it like

Think of it like a photo of your room. Next time, you spot what moved.

## Definition

A snapshot test saves the output of some code the first time it runs. Later runs are compared against it. The output might be a chunk of HTML, a JSON reply or a picture. If anything changes, the test fails and shows the difference. You then either fix the bug or accept the new output as the new snapshot. Jest made the idea popular with toMatchSnapshot.

## Example

Jack's snapshot test saves the HTML of his price box. When a change drops the currency sign, the test fails and shows the missing pound sign.

## Example code

```javascript
test('price box', () => {
  expect(render(price)).toMatchSnapshot();
});
```

The first run saves the output; later runs must match it.

## Why it matters

It catches changes nobody meant to make. You do not have to write a check for every detail.

## Common mistake

Accepting each new snapshot without reading what changed. Then the test lets bugs through.

## Three principles

- **Save once.** The first run is the answer.
- **Fail on any change.** And show the difference.
- **Read before you accept.** Or it means nothing.

## Related terms

- [Unit Test](https://learn.benibix.com/term/development/unit-test)
- [Regression Test](https://learn.benibix.com/term/development/regression-test)
- [Jest](https://learn.benibix.com/term/development/jest)
- [Assertion](https://learn.benibix.com/term/development/assertion)

---

Source: https://learn.benibix.com/term/development/snapshot-test
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
