Skip to Content
React 16 Tooling
book

React 16 Tooling

by Adam Boduch, Christopher Pitt
April 2018
Intermediate to advanced content levelIntermediate to advanced
298 pages
6h 34m
English
Packt Publishing
Content preview from React 16 Tooling

React component snapshots

React components render output. Naturally, you want part of your component unit tests to ensure that the correct output is created. One approach is to render the component to a JS-based DOM, and then to perform individual assertions on the rendered output. This would be a painful test writing experience to say the least.

Snapshot testing allows you to generate a snapshot of rendered component output. Then, each time your test runs, the output is compared to the snapshot. If something looks different, the test fails.

Let's modify the default test for the App component that create-react-app adds for you to make it use snapshot testing. Here's what the original test looked like:

import React from 'react'; import ReactDOM ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro React 16

Pro React 16

Adam Freeman

Publisher Resources

ISBN: 9781788835015Supplemental Content