nextjs-vitest

Set up Vitest testing environment for Next.js projects

tenkoh/skills33 installsMITSynced Aug 22

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI
---
name: nextjs-vitest
description: Set up Vitest testing environment for Next.js projects
license: MIT
---

Set up Vitest testing environment for a Next.js project.

## Steps

### 1. Install required packages

Run the following command:

```bash
npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths @testing-library/jest-dom @testing-library/user-event
```

### 2. Create vitest.config.mts

Create `vitest.config.mts` in the project root:

```typescript
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

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

### 3. Create vitest.setup.ts

Create `vitest.setup.ts` in the project root:

```typescript
import "@testing-library/jest-dom/vitest";
```

### 4. Verify completion

Confirm all files have been created correctly.

More Testing skills

← All Testing skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY