Introduction

Jest is a test runner which can be used for running tests for any javascript framework or code. It is not dependant on React. The features provided by Jest are framework agnostic ie non tied specifically to any framework.

So if you understand Jest, then it would be useful not just for React, but for testing other javascript code as well.

Create React App

If you are using Create React App (CRA), then the jest is pre configured with it. So you can skip the below instructions. You can directly move to next tutorial.

Installing Jest

You can install jest using yarn by following command


yarn add --dev jest

You can install jest using npm by following command


npm install --save-dev jest

Getting started with config

You need to specify the config for jest to make it work. It can done interactively using the following command


jest --init

This will create a config file for you in the project.

Introduction

Jest is a test runner which can be used for running tests for any javascript framework or code. It is not dependant on React. The features provided by Jest are framework agnostic ie non tied specifically to any framework.

So if you understand Jest, then it would be useful not just for React, but for testing other javascript code as well.

Create React App

If you are using Create React App (CRA), then the jest is pre configured with it. So you can skip the below instructions. You can directly move to next tutorial.

Installing Jest

You can install jest using yarn by following command


yarn add --dev jest

You can install jest using npm by following command


npm install --save-dev jest

Getting started with config

You need to specify the config for jest to make it work. It can done interactively using the following command


jest --init

This will create a config file for you in the project.