vitest-testing

Writes, runs, and diagnoses Vitest unit and integration tests for Next.js TypeScript projects.

Updated Jul 9, 2026
One-click install
npx skills add https://github.com/DimonikRV/ghost-pilot-project --skill vitest-testing-dimonikrv
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: vitest-testing
Source: https://github.com/DimonikRV/ghost-pilot-project/tree/main/.claude/skills/vitest-testing
Command: npx skills add https://github.com/DimonikRV/ghost-pilot-project --skill vitest-testing-dimonikrv

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests for a Next.js application with Clerk authentication, Prisma, and Liveblocks requires intricate mock setup, correct hoisting order, and knowledge of project-specific conventions. This Skill provides the exact templates, mock patterns, and commands needed to write passing tests without trial and error. ## Core Features & Use Cases - Ready-to-use test templates: Copy-paste templates for unit tests, hook tests, and API route integration tests with mocked Clerk auth and Prisma. - Mock patterns that work: Enforces the critical vi.hoisted() pattern for Prisma mocks and the correct mocking order (Clerk before Prisma before route imports) to avoid common Vitest pitfalls. - Full test command reference: Run unit, integration, coverage, and E2E suites, plus targeted single-file or pattern-matched test execution for debugging. - Use Case: You need to add integration tests for a new API route. The Skill provides the integration template with setMockAuth/resetMockAuth helpers, the hoisted Prisma mock, and the command to run just that file. ## Quick Start Ask the assistant to write an integration test for a specific API route with mocked Clerk authentication and Prisma, then run it with the appropriate vitest command.

Frequently Asked Questions about vitest-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write integration tests for Next.js API routes with Vitest?▼

Mock @clerk/nextjs/server and @/lib/prisma using vi.hoisted() before importing the route handler, then call the handler with a NextRequest and assert on the response status and body. Use setMockAuth(null) to test unauthenticated 401 responses.

How to mock Prisma in Vitest tests?▼

Define the Prisma mock inside vi.hoisted() so it is available when Vitest hoists vi.mock calls, then register it with vi.mock("@/lib/prisma", () => ({ default: mockPrisma })). Each model method should be a vi.fn() with mockResolvedValue defaults.

How do I mock Clerk authentication in Vitest?▼

Use the setMockAuth and resetMockAuth helpers from tests/mocks/clerk.ts together with a vi.mock of @clerk/nextjs/server. Call setMockAuth("user_123") for authenticated requests or setMockAuth(null) for unauthenticated ones, and reset in beforeEach.

Why does my Vitest mock not apply to the imported module?▼

The most common cause is importing the route handler before the vi.mock() calls, or defining mock data outside vi.hoisted(). Vitest hoists vi.mock to the top of the file, so mock factories must not reference variables declared later.

Can Vitest run Playwright E2E tests in the same suite?▼

No. The Vitest config explicitly excludes tests/e2e, which contains Playwright specs. Run E2E tests separately with npm run test:e2e, while Vitest handles unit and integration tests under tests/unit and tests/integration.