Exploring unit testing
Unit testing is a way of testing the smallest piece of code that you have logically defined within your application. During unit testing, we isolate a small part of the code and verify that it is behaving as intended independently from the rest of the code base. We instantiate this piece of code, invoke it, and then observe its behavior. If the observed behavior matches what we expected, then we know that our code is doing what it should be. By setting up a multitude of these tests, we can have a better understanding of where something has broken when we edit large parts of the code base.
Within React and Gatsby, there are multiple different ways in which you can set up unit tests. Here, we will focus on one of the most popular combinations – Jest and React Testing Library. Let's create a structure within our repository that will allow us to test our site using these tools:
- Install the necessary dependencies:
npm install -D jest babel-jest...