Search⌘ K

Writing Unit Tests for Our Application

Explore how to write and organize unit tests for React applications using Jest. Understand the importance of fast tests, how to handle test failures, and strategies to avoid issues like infinite loops during testing.

Unit tests - expect

When setting up the tests, we have the option of grouping all the expect calls within a single test function. This can be a good idea if multiple tests require the same setup steps and those steps are slow. In this case, combining them reduces the work that needs to be done and can speed up the tests. On the other hand, if our tests are slow, then they aren’t good unit tests. Unit tests should be fast because they will be run on every commit to the repository. Most of the time, it’s better to put the expect calls in separate functions. Once ...