React is a javascript library for building user interfaces. Writing unit test cases for the application is good practice. We will be using the jest library to write the unit test cases in React.

There are many types of components that can be unit tested. We have routes, async functions, timer functions, states, redux, lifecycle methods, charts, etc that need to be unit tested.

Why developers don't write unit test case

One of the main reasons the developers do not write test cases is that writing correct and useful test cases is hard. When you look into the examples in test libraries like jest, they are very simple. They test some simple functions. But in reality, when working on real projects, things are not always ideal. You need to write code that is testable. You need to know which code needs to be tested and which code would be better off with snapshot testing or integration testing.

Writing unit test cases for different components in React

In this series of tutorials, we will look into testing all these aspects mentioned above, so that you get a complete picture of unit testing in React. By the end of the tutorial series, you will be a developer who can write test cases easily and can start working in Test Driven Development (TDD) mode.

We are going to look into setting up the environment for jest. Then we will look into writing unit test cases specific to each type of component - example writing unit test case for routes, async functions, etc. Then we will look into different types of testing available in React.