- Home
- Skills
- Secondsky
- Claude Skills
- Vitest Testing
vitest-testing_skill
- TypeScript
52
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill secondsky/claude-skills --skill vitest-testing- SKILL.md4.6 KB
Overview
This skill provides expert guidance for testing TypeScript and JavaScript projects using Vitest. It focuses on fast unit and integration tests with native ESM, Vite-powered HMR, and comprehensive mocking features. The content covers installation, configuration, running tests, assertions, mocking, timers, coverage, and integration testing. It is aimed at making tests reliable, fast, and easy to maintain in modern JS/TS stacks.
How this skill works
The skill explains how to configure Vitest for node or jsdom environments, set coverage providers and thresholds, and include test file patterns. It describes common test workflows: running tests in watch or CI mode, using parametrized tests, and generating coverage reports. It covers assertion styles, function and module mocking with vi, fake timers, and integration testing patterns with supertest. Practical commands and configuration snippets are provided for immediate use.
When to use it
- When you need fast unit tests with native ESM and Vite integration
- When adding or maintaining tests for TypeScript or modern JavaScript projects
- When you require reliable mocking for modules, timers, or async code
- When you want Vite-powered HMR for test-driven development workflows
- When you need coverage reports and threshold enforcement for CI
Best practices
- Keep one test file per source file and mirror naming (e.g., math.ts → math.test.ts)
- Group related specs with describe() and use descriptive test names
- Mock only external dependencies; avoid over-mocking internal logic
- Use beforeAll/afterAll for expensive fixtures and beforeEach/afterEach for per-test setup
- Run independent async tests concurrently and share fixtures when appropriate
- Aim for sensible coverage thresholds (80%+), but prioritize meaningful tests
Example use cases
- Unit testing a utility library with parametrized tests and fast assertions
- Integration testing an Express/Koa API using supertest and Vitest
- Mocking network modules during component tests to isolate logic
- Using fake timers to test scheduled behaviors and date-dependent code
- Running CI pipelines with coverage enforcement and HTML report generation
FAQ
Use Bun for fastest performance when available; npm/node works fine too.
How do I run tests in CI?
Run tests once with bun test --run or the npm equivalent and include --coverage to collect coverage.