Tech vitest

From ravnhq/ai-toolkit · View interactive version

Tech vitest is an AI agent skill from the GitHub repository ravnhq/ai-toolkit. Vitest testing framework for modern JavaScript. Unit and integration tests with Jest-compatible API, native TypeScript, Vite integration, MSW v2 for HTTP mocking, and snapshot testing. Covers vi.mock hoisting, fake timers, test isolation, and async patterns. Use when writing tests with Vitest, mocki

How to use this skill

Skill file

Vitest Testing Framework

Fast, Vite-powered testing framework with Jest-compatible API and native ESM. Vitest excels at:

Core challenge: test isolation. Vitest's hoisting rules for vi.mock() require vi.hoisted() for shared mock state. MSW v2 changes handler APIs. Snapshot updates must be intentional.

Workflow

When setting up tests or adding test cases:

  1. Identify scope — What behavior? (unit/integration/e2e?)
  2. Determine dependencies — HTTP? Timers? Other modules?
  3. Choose strategy — vi.mock() with hoisting for modules, MSW for HTTP, fake timers for time
  4. Hoist shared state — Use vi.hoisted() if mocks need variables from test scope
  5. Set up handlers — MSW server in beforeAll(), reset in afterEach()
  6. Assert & snapshot — Use matchers; snapshot only stable outputs
  7. Validate — vitest --watch with coverage checks

Rules

Tests are organized by concern:

See rules/ for implementation patterns and examples.

Examples

Positive Trigger

User: "Mock the API client in this Vitest test so it returns a fake response."

Expected behavior: Use tech-vitest guidance, apply vi.mock() with hoisting rules and MSW patterns.

Non-Trigger

User: "Set up a PostgreSQL database schema for user accounts."

Expected behavior: Do not prioritize tech-vitest; choose a more relevant skill or proceed without it.

Troubleshooting

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.