React tree Snapshot Testing

Now that you have seen a real-world testing example you may think that writing so many tests for a single component is a time-consuming task and not worth it.

Checking for each variation of text, value, and class name is laborious and it requires much code to cover all instances. However, most of the time, whenever we test components, the most important thing for us is that the output is correct and that it does not change unexpectedly. There is a new feature introduced in Jest that helps with this problem and it's called Snapshot Testing.

Snapshots are pictures of the component with some props at a given point in time. Every time we run the tests, Jest creates new pictures and it compares them with the previous ones ...

Get React Design Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.