Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Get Started with Jest | Jest
Expert React

bookGet Started with Jest

Jest is a testing framework widely used in React projects. It provides a bunch of useful utilities. Jest is easy to configure, supports code coverage, and is a powerful tool for testing React components and applications.

Setting up a new React project with Jest

Step 1: Create a new React project

Let's create a new React project using create-react-app in the terminal:

npx create-react-app .

Step 2: Install Jest library

Since Jest is not pre-installed with create-react-app, we must install it separately to enable testing for the React project. To install Jest, open the terminal and run the following command:

npm install jest

This will download and install Jest. Additionally, it will update the package.json file to include Jest in the dependencies section. The package.json should now include Jest similar to the following:

"dependencies": {
  "@testing-library/jest-dom": "^5.16.5",
  "@testing-library/react": "^13.4.0",
  "@testing-library/user-event": "^13.5.0",
  "jest": "^27.5.1",
  "react": "^18.2.0",
  "react-dom": "^18.2.0",
  "react-scripts": "5.0.1",
  "web-vitals": "^2.1.4"
},

Project overview

The Jest learning will consist of theoretical and practical parts. In the following chapters, we will learn how to write tests for the Counter App. This approach will help us understand the theory better and apply our knowledge immediately through practical examples.

Note

The app has been entirely built but still lacks tests. Please take the time to inspect the app and ensure that everything is clear. As in the following chapters, we will dive into testing.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 2

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Still meg spørsmål om dette emnet

Oppsummer dette kapittelet

Vis eksempler fra virkeligheten

Awesome!

Completion rate improved to 1.96

bookGet Started with Jest

Sveip for å vise menyen

Jest is a testing framework widely used in React projects. It provides a bunch of useful utilities. Jest is easy to configure, supports code coverage, and is a powerful tool for testing React components and applications.

Setting up a new React project with Jest

Step 1: Create a new React project

Let's create a new React project using create-react-app in the terminal:

npx create-react-app .

Step 2: Install Jest library

Since Jest is not pre-installed with create-react-app, we must install it separately to enable testing for the React project. To install Jest, open the terminal and run the following command:

npm install jest

This will download and install Jest. Additionally, it will update the package.json file to include Jest in the dependencies section. The package.json should now include Jest similar to the following:

"dependencies": {
  "@testing-library/jest-dom": "^5.16.5",
  "@testing-library/react": "^13.4.0",
  "@testing-library/user-event": "^13.5.0",
  "jest": "^27.5.1",
  "react": "^18.2.0",
  "react-dom": "^18.2.0",
  "react-scripts": "5.0.1",
  "web-vitals": "^2.1.4"
},

Project overview

The Jest learning will consist of theoretical and practical parts. In the following chapters, we will learn how to write tests for the Counter App. This approach will help us understand the theory better and apply our knowledge immediately through practical examples.

Note

The app has been entirely built but still lacks tests. Please take the time to inspect the app and ensure that everything is clear. As in the following chapters, we will dive into testing.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 2
some-alt