Installation

First, we need to make sure we have Jest installed. Jest is a regular third-party package that is installable via the npm and Yarn registries.

If we are working inside a Create React App project, Jest is already installed as the test runner. Both were created by and are maintained by Meta. Yarn was also created by this team. CRA also ships with React Testing Library.

At the time of writing this, CRA ships with Jest as a production dependency. There are differences in opinion within the React community on this, but because it is inherently not used in production, we suggest moving it to devDependencies in package.json. Otherwise, install it with one of the following commands:

yarn add jest --dev
npm install jest --save-dev

Now that it’s installed, we need to configure Jest for our needs.

Running tests

Get hands-on with 1400+ tech skills courses.