From the course: React: Testing and Debugging
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Snapshot testing with Jest - React.js Tutorial
From the course: React: Testing and Debugging
Snapshot testing with Jest
- [Instructor] Jest snapshots allow us to test a UI at different points in time and prevent any unexpected changes. When change happens, either intentionally or not, our tests with throw an error to let us know. This way we can decide whether to update the snapshot or look into why the snapshot changed. Jest accomplishes this because it renders our component into a JSON file. And then takes a snapshot of this file. Then whenever we run our test, Jest compares the snapshot with the latest rendered output. If there is any difference between them, we get notified. So let's first install the package, then we'll refactor our app test to do the snapshots. So let's bring up a terminal inside of VS Code, so I'm going to click on Terminal, New Terminal. And then I'm going to do npm i, which is short for install react-test-renderer like so. Once this is installed, you can go ahead and close the terminal and then…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.