From the course: React: Testing and Debugging
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
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.
Contents
-
-
-
-
(Locked)
Test strings with matchers3m 46s
-
(Locked)
Test numbers with matchers5m 46s
-
(Locked)
Solution: Test numbers with matchers3m 17s
-
(Locked)
Test arrays and objects with matchers7m 32s
-
(Locked)
Solution: Test object with matchers3m 8s
-
(Locked)
Code coverage reports3m 15s
-
(Locked)
Snapshot testing with Jest5m 13s
-
(Locked)
Organize your tests with describe()4m 51s
-
(Locked)
-
-
-