Using Vitest
Vitest (https://vitest.dev/) is the testing framework for Vite projects. It is also possible to use Jest in Vite projects, and there are libraries that provide Vite integration for Jest (for example, https://github.com/sodatea/vite-jest). In this book, we will use Vitest because it is easier to start using it with Vite. Vitest is similar to Jest, and it provides test
, describe
, and expect
, which we learned about in the Jest section.
In this section, we will create tests with Vitest and the React Testing Library for the frontend project that we used in Chapter 14, Styling the Frontend with MUI.
Installing and configuring
The first step is installing Vitest and the React Testing Library to our project:
- Open the project in Visual Studio Code. Move to your project folder in the terminal and execute the following
npm
command inside your project folder:npm install -D vitest @testing-library/react @testing-library/jest- dom jsdom
The
-D...