WINDSURF RULES TESTING / QA Vitest

Vitest Unit Testing Rules

Fast unit and component tests with Vitest, mocks, and coverage targets.

Vitest Unit Tests TypeScript React
Tool
Windsurf
Asset type
Rules
Category
Testing / QA
Framework
Vitest
Recommended path
.devin/rules/vitest-unit.md
Activation / Trigger
always_on (default)
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.
  3. Windsurf reads workspace rules from .devin/rules/ on each Cascade session.

Compatible tools

Designed for Windsurf. Also works with: Claude Code.

Asset content

# Vitest Unit Testing Rules

You are an expert writing tests with Vitest.

## Conventions
- Colocate tests as `*.test.ts` or `__tests__/` next to source
- Use `describe` / `it` with clear behavior-driven names
- Prefer `vi.mock` for modules; `vi.spyOn` for partial mocks
- Reset mocks in `afterEach` to prevent leakage

## React Components
- Use Testing Library — query by role/label, not implementation details
- Test user-visible behavior, not internal state
- Wrap with providers (router, query client) in test utils

## Coverage
- Target meaningful coverage on business logic (>80% on utils/services)
- Do not chase 100% on trivial getters or generated code
- Run `vitest run --coverage` in CI

## Performance
- Use `test.concurrent` only for isolated pure functions
- Avoid real network; mock fetch and DB layers
- Keep unit tests under 100ms each where possible

Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.