Skip to content
Back to skills

Using Vitest

ASecurity

Use when writing or editing Vitest 3+ tests in TypeScript. Triggers on `.test.ts`, `.spec.ts`, `vitest.config.*` files, test setup, mocks, HTTP or CORS assertions, or type safety in tests, even when the user doesn't say 'Vitest'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 30, 2026
ai-agentstypescriptgonodetestingapi

Works with

  • api

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill using-vitest --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Using Vitest?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Using Vitest
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-using-vitest/badge)](https://www.skillsdirectory.com/skills/xonovex-using-vitest)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: using-vitest
description: "Use when writing or editing Vitest 3+ tests in TypeScript. Triggers on `.test.ts`, `.spec.ts`, `vitest.config.*` files, test setup, mocks, HTTP or CORS assertions, or type safety in tests, even when the user doesn't say 'Vitest'."
---

# Vitest Testing Guidelines

For framework-independent test design: Arrange-Act-Assert, FIRST, and choosing/naming test doubles, see **authoring-tests**; this skill covers only Vitest-specific mechanics.

## Requirements

- Vitest ≥ 3, TypeScript ≥ 5.8

## Essentials

- **Type safety** - Cast `res.json()` to declared interfaces, see [references/type-safety.md](references/type-safety.md)
- **HTTP testing** - Assert the status the middleware actually sends, see [references/http-testing.md](references/http-testing.md)
- **Timestamp testing** - Avoid flaky comparisons; verify existence or add delays, see [references/timestamp-testing.md](references/timestamp-testing.md)
- **TypeScript config** - Include test paths; verify project reference levels, see [references/typescript-config.md](references/typescript-config.md)
- **Test organization** - Mirror API structure under `test/` with nested describe blocks, see [references/test-organization.md](references/test-organization.md)

## Gotchas

- Vitest transforms (`vite-node`) differ from Jest: `__dirname`/`__filename` work in CommonJS but not ESM tests without polyfills
- `vi.spyOn` returns the spy; `vi.fn` creates a new mock: confusing them passes type checks but breaks call-tracking assertions
- `expect.assertions(n)` in async tests catches missed awaits, without it, a forgotten `await` lets the test pass spuriously
- Watch mode caches module graphs; changing `vitest.config.ts` requires a full restart to pick up new transforms

## Progressive disclosure

- Read [references/type-safety.md](references/type-safety.md) - Load when calling `res.json()` or test variables lose type information
- Read [references/http-testing.md](references/http-testing.md) - Load when asserting HTTP status codes or testing CORS OPTIONS requests
- Read [references/timestamp-testing.md](references/timestamp-testing.md) - Load when tests fail intermittently due to timing
- Read [references/mock-patterns.md](references/mock-patterns.md) - Load when creating mocks or stubs for tests
- Read [references/typescript-config.md](references/typescript-config.md) - Load when test files aren't recognized by TypeScript or reference imports fail
- Read [references/test-organization.md](references/test-organization.md) - Load when structuring test suites for large APIs

Files in this skill

  • SKILL.md2.5 KB
  • eval-output.json2.5 KB
  • eval-trigger.json5.6 KB
  • moon.yml86 B
  • references/http-testing.md670 B
  • references/mock-patterns.md275 B
  • references/test-organization.md352 B
  • references/timestamp-testing.md602 B
  • references/type-safety.md603 B
  • references/typescript-config.md680 B
  • sources.json972 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.