Introducing Vitest
Vitest is a unit test framework built on Vite, designed for speed and minimal configuration. It serves as a replacement for various testing tools such as Jest, Mocha, and Chai. Since Vitest is built on top of the Jest API, if you already know how to use Jest, it works in a similar manner.
In this context, we will utilize Vite, a build tool that aims to provide a fast and lean development experience for modern web projects.
Firstly, you need to install Vite globally with:
npm install vite -g
After it’s installed, you need to create your first project with the npm
command:
npm create vite@latest
It will ask you for the project name. You can use my-first-vite-project
, then for the framework you want to use (React
), and finally, choose the variant (TypeScript
):
Figure 16.6: npm create vite@latest
Next, you need to install the project dependencies and run the npm run dev
command. If you do so, you will see something similar...