In this blog post, we will install and setup Vitest in order to be able to write and run unit tests.
Install Vitest
In the root directory of your project type in the command line npm install -D vitest
.
Modify Vite configuration file
Next, modify the file vite.config.ts
:
import { defineConfig } from 'vitest/config'
import react from '@vite/plugin-react'
export default defineConfig({
plugins: [react()]
})
Add Vitest to package.json
Add the following in the scripts
section in package.json
:
"test": "vitest"
Save and exit. Now, you can run Vitest.