In this tutorial, we will be looking into how to set up and add unit tests to React components using Jest and Enzyme. Jest and Enzyme are different tools, both together to provide flexible and creative testing abilities. Before we start to write the test, we need to set up the react application. Here I have used create-react-app for setting up theReact application.

By running following command we can install create-react-app,

$ npm install create-react-app

Now we can create the react app using the following command,

$ npm init react-app my-react-app

Now we can change the directory to the new React app directory created and start the development server like following,

$ cd my-react-app/

$ npm start

Now you can see the confirmation message of a compilation of app and port number of React application, using this port number we can access the react application.

Now you can open the React application on your favorite text editor and change the scr/App.js component based on your needs. For this tutorial, I have made an application that lists the employee’s information.

#react js #jest & #enzyme #react #react app

Performing Unit Testing With React JS Components Using Jest & Enzyme
11.80 GEEK