Testing Vitest

Enforce Vitest testing standards for unit and integration tests.

7|Updated Dec 15, 2025
One-click install
npx skills add https://github.com/leaderiop/hex-di --skill testing-vitest
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Testing Vitest
Source: https://github.com/leaderiop/hex-di/tree/main/.claude/skills/testing-vitest
Command: npx skills add https://github.com/leaderiop/hex-di --skill testing-vitest

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides Claude Code with guidelines for writing, organizing, and running tests with Vitest to ensure fast, reliable feedback and consistent test structure.

Core Features & Use Cases

  • Test organization: Standard test file locations and naming.
  • Assertion & mocks: Recommended patterns for vitest.
  • Use Case: When adding unit tests for a React component, use Vitest conventions to align tests.

Quick Start

In a project using Vitest, tell Claude to apply Vitest standards when creating tests or updating test suites.

Frequently Asked Questions about Testing Vitest

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests with Vitest?

Vitest is a fast unit testing framework for JavaScript projects. Write tests by creating `.test.js` or `.spec.js` files, import your code and Vitest utilities, define test cases with `describe` and `it`, and use assertions to verify behavior. Vitest integrates seamlessly with modern tooling and runs tests in parallel for quick feedback.

What are Vitest naming conventions and test organization best practices?

Organize tests in dedicated test directories mirroring your source structure, name test files with `.test.js` or `.spec.js` suffixes, and group related tests with `describe` blocks. Use clear, descriptive test names that explain what behavior is being verified. This structure enforces consistency across codebases and makes tests easier to maintain and discover.

How do I set up mocks and assertions in Vitest?

Vitest provides built-in mocking utilities and assertion methods. Use `vi.mock()` to mock modules, `vi.fn()` to create mock functions, and chain assertion methods like `.toEqual()`, `.toHaveBeenCalled()`, and `.toBeDefined()`. Establish setup and teardown with `beforeEach` and `afterEach` hooks to isolate test state and ensure reliable, predictable test execution.

Can I use Vitest for integration tests and CI pipelines?

Yes, Vitest supports integration tests alongside unit tests within the same framework. Configure coverage thresholds in `vitest.config.js`, integrate Vitest with CI systems like GitHub Actions or GitLab CI by running `vitest` in your pipeline, and collect coverage reports to enforce code quality standards across your project.

What coverage thresholds should I enforce with Vitest?

Set coverage thresholds in Vitest configuration to maintain code quality standards. Common targets include 80% line coverage, 75% branch coverage, and 80% function coverage, adjusted to your project's risk profile. Vitest fails CI builds when thresholds aren't met, ensuring consistent test quality across your codebase.

How do I configure Vitest for my project?

Create a `vitest.config.js` file to define test environment, coverage settings, mock behavior, and CI integration options. Specify test file patterns, coverage thresholds, and assertion libraries. This centralized configuration enforces consistent testing standards and ensures Vitest aligns with your project's architecture and quality requirements.