Vitest Alternative

+15 Mana ✨

Vitest is a Vite-powered test runner that's becoming increasingly popular.

Why Vitest?

  • Faster: Uses Vite's native ESM support.
  • Compatible: Jest-compatible API.
  • HMR: Tests re-run instantly on changes.

Installation

bash
npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/jest-dom

Configuration

Create vitest.config.ts:

typescript
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  test: {
    environment: 'jsdom',
    setupFiles: ['./vitest.setup.ts'],
    globals: true,
  },
});

Create vitest.setup.ts:

typescript
import '@testing-library/jest-dom/vitest';

Package.json Script

json
{
  "scripts": {
    "test": "vitest",
    "test:run": "vitest run"
  }
}

Vitest runs in watch mode by default, use vitest run for CI.

✓ Completed