
Vitest Has a Free API That Makes Unit Testing in Vite Projects Lightning Fast
Vitest is the native test runner for Vite. Same config, same transforms, same plugin ecosystem. Tests run with Vite's speed — instant HMR, native ESM, no Babel. Quick Start npm install -D vitest // vite.config.ts — that's it, Vitest reads your existing Vite config import { defineConfig } from ' vitest/config ' export default defineConfig ({ test : { globals : true } }) Basic Test import { describe , it , expect } from ' vitest ' describe ( ' math ' , () => { it ( ' adds numbers ' , () => { expect ( 1 + 1 ). toBe ( 2 ) }) }) Jest-Compatible API import { describe , it , expect , vi , beforeEach } from ' vitest ' // Mocking const mockFn = vi . fn () vi . mock ( ' ./api ' , () => ({ fetchData : vi . fn () })) // Spying const spy = vi . spyOn ( console , ' log ' ) // Timers vi . useFakeTimers () vi . advanceTimersByTime ( 1000 ) Drop-in replacement for Jest. Same describe , it , expect , vi (instead of jest ). Watch Mode (Instant Feedback) npx vitest # watch mode by default npx vitest run #
Continue reading on Dev.to JavaScript
Opens in a new tab

