vitest-testing

Configure Vitest projects with unit and integration tests using mocking and snapshots.

75|9|Updated Dec 21, 2025
One-click install
npx skills add https://github.com/anderskev/beagle --skill vitest-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest-testing
Source: https://github.com/anderskev/beagle/tree/main/skills/vitest-testing
Command: npx skills add https://github.com/anderskev/beagle --skill vitest-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Vitest testing patterns establish best practices for unit/integration tests, mocks, snapshots, and coverage.

Core Features & Use Cases

  • Configuring vitest.config and setup files
  • Common assertions, mocking, and snapshots
  • Coverage configuration and type testing

Quick Start

Set up a Vitest config file, write a basic test, and run the test suite.

Frequently Asked Questions about vitest-testing

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

FAQPage Schema
How do I set up Vitest for unit and integration testing in Node.js projects?

Vitest is a unit testing framework for Node.js that uses a vitest.config.ts file to configure test environments, reporters, and coverage settings. Create a config file, write tests using describe and it blocks, then run the test suite with the vitest command to execute all tests concurrently.

What's the best way to mock functions and modules in Vitest tests?

Vitest provides vi.mock and vi.fn utilities to mock modules and individual functions. Use vi.mock at the top of test files to replace module implementations, and vi.fn to create spy functions that track calls and return values, enabling isolated unit tests.

How do I configure code coverage thresholds in Vitest?

Vitest's coverage configuration in vitest.config.ts enforces minimum coverage percentages across lines, functions, branches, and statements. Set thresholds in the coverage object to fail test runs when coverage drops below specified levels, ensuring comprehensive test quality.

Can I use snapshots in Vitest to verify component output?

Vitest snapshots capture expected output from functions or components and compare against future runs to detect unintended changes. Use toMatchSnapshot assertions to save baseline snapshots, then review diffs when snapshots fail to catch regressions.

Does Vitest support type testing and environment isolation?

Vitest provides test environment setup files to configure global state, mocks, and fixtures, plus concurrent execution with test isolation to prevent state leakage between tests. Type testing capabilities verify TypeScript type definitions and inference patterns.