🧪Snapshot Test
Also known as Snapshot Testing, toMatchSnapshot
A test that saves some output once, then fails if it ever changes.
Think of it like
Think of it like a photo of your room. Next time, you spot what moved.
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.
Why it matters
It catches changes nobody meant to make. You do not have to write a check for every detail.
Definition
Example code
javascript
test('price box', () => {
expect(render(price)).toMatchSnapshot();
});Common mistake
Key takeaways
- 1Save once. The first run is the answer.
- 2Fail on any change. And show the difference.
- 3Read before you accept. Or it means nothing.