Implementing React tests with Jest
In this section, we areĀ goingĀ to turn our attention to creating automated tests for the frontend with Jest. Jest is theĀ de facto testing tool in theĀ ReactĀ community and is maintained by Facebook. Jest is included inĀ Create React AppĀ (CRA) projects, which means that it has already been installed andĀ configuredĀ in our project.
We areĀ goingĀ to start by testing a simple function so that we can get familiarĀ with Jest before moving on to testing a React component.
Getting started with Jest
We'll start to get familiar with Jest by adding some unit tests to the mapQuestionFromServer
function in QuestionsData.ts
. So, let's openĀ our frontend project in Visual Studio Code and carry out the following steps:
- Remove the example test that was installed when the project was created with Create React App by removing the
App.test.tsx
file in thesrc
folder. - Create a new...