⚡ Vitest

👋 FYI, this note is over 6 months old. Some of the content may be out of date.
On this page

vitest.config.ts Jump to heading

/// <reference types="vitest" />
/// <reference types="vite/client" />

import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [react(), tsconfigPaths()],
test: {
environment: 'happy-dom',
setupFiles: ['./vitest.setup.ts'],
},
})

vitest.setup.ts Jump to heading

Add anything to this file that you want run before each test.

If you use the default vitest config value for globals and you want to use jest-dom:

import matchers from '@testing-library/jest-dom/matchers'
import { expect } from 'vitest'

expect.extend(matchers)

If you want jest-dom and use globals: true in your config:

import '@testing-library/jest-dom'

If you’re using Remix:

import { installGlobals } from '@remix-run/node/globals'
installGlobals()

← Back home