Home / Companies / LogRocket / Blog / Post Details
Content Deep Dive

Using Jest for React screenshot testing

Blog post from LogRocket

Post Details
Company
Date Published
Author
Alexander Solovyev
Word Count
1,151
Language
-
Hacker News Points
-
Summary

Screenshot testing is a method used to compare the visual aspects of an application's user interface by taking screenshots of the old and new versions and highlighting differences, typically using red markers. Two popular libraries for conducting screenshot tests in React applications are jest-image-snapshot and react-screenshot-test, both of which utilize Puppeteer for capturing screenshots. The jest-image-snapshot library requires some configuration on the application side, while react-screenshot-test provides its own API and requires more setup due to its capability of isolating and testing individual components. Examples of using each library demonstrate how they can capture screenshots in different states and resolutions, with jest-image-snapshot involving a more direct Puppeteer workflow and react-screenshot-test offering a convenient API for testing multiple component variations. Both libraries have their merits, with jest-image-snapshot being beneficial for projects already using Puppeteer for end-to-end tests and react-screenshot-test excelling in pairing components with visual validation across various screen resolutions. They can be used together in a CI workflow, offering flexibility in testing strategies.