# Write Better Vitest Tests

Teams often lose time translating Vitest documentation into correct test patterns. This skill gives Claude, Codex, and Claude Code focused guidance for Vitest APIs, configuration, mocking, coverage, and fixtures.

## Install

```bash
npx skillstore add antfu/vitest
```

## Metadata

- - Slug: antfu-vitest
- - Version: 1.0.0
- - Author: antfu
- - GitHub username: antfu
- - License: MIT
- - Repository: https://github.com/antfu/skills/tree/main/skills/vitest/
- - Ref: main
- - Supported tools: Claude, Codex, Claude Code
- - Risk level: low
- - Risk factors: external\_commands, scripts, network, env\_access
- - Quality score: 74
- - Public page: https://skillstore.pages.dev/skills/antfu-vitest
- - Manifest: https://skillstore.pages.dev/api/skills/antfu-vitest/manifest

## Capabilities

- Explains Vitest configuration with vite.config.ts and vitest.config.ts.
- Guides use of test, describe, expect, hooks, and concurrent test APIs.
- Provides patterns for vi mocks, spies, fake timers, and environment stubs.
- Covers coverage settings, snapshots, filtering, tags, and watch mode commands.
- Supports browser-like test environments such as jsdom and happy-dom.
- Includes TypeScript type testing with expectTypeOf and assertType.

## Use Cases

- Add Unit Tests To A Vite App: Create focused tests using test, describe, expect, setup files, and project configuration.
- Convert Jest Patterns To Vitest: Map common Jest-style assertions, mocks, snapshots, and lifecycle hooks to Vitest APIs.
- Improve CI Test Reliability: Use run mode, filtering, retries, coverage, sharding, and concurrency guidance for stable automation.

## Prompt Templates

### Create A Basic Test

```
Use the Vitest skill to write unit tests for this function. Include describe, test, and expect patterns.
```

### Configure Vitest For Vite

```
Use the Vitest skill to configure Vitest for a Vite TypeScript project with jsdom and setup files.
```

### Mock Modules And Timers

```
Use the Vitest skill to mock this module, add fake timer tests, and explain cleanup steps.
```

### Design A CI Test Strategy

```
Use the Vitest skill to propose CI settings for coverage, sharding, retries, filtering, and snapshot handling.
```

## Limitations

- It is based on Vitest 3.x documentation generated on 2026-01-28.
- It does not run tests or inspect project failures by itself.
- It does not replace project-specific test design decisions.
- It may need verification against newer Vitest releases.

## Best Practices

- Use context expect in concurrent tests and snapshot assertions.
- Restore mocks, timers, globals, and environment stubs after each test.
- Run Vitest in single-run mode for CI and lint-staged workflows.

## Anti Patterns

- Do not leave test.only or describe.only in committed test files.
- Do not mix real timers with fake timer assertions without cleanup.
- Do not rely on browser APIs without selecting a matching test environment.

## Security Audit

- - Safe to publish: true
- - Audited at: 2026-06-28T09:55:34.243\+00:00
- - Summary: Static analysis reported many command, script, network, and environment patterns, but review found they are Vitest documentation examples and metadata. No prompt injection, credential exfiltration, malicious command execution, or hidden runtime behavior was found in the reviewed files.

## Stats

- - Views: 240
- - Downloads: 11
- - Favorites: 0
- - Popularity score: 0
