vitest

Run JavaScript/TypeScript unit and integration tests with Vitest, including mocked external dependencies and React hooks/API checks.

Updated Apr 5, 2023
One-click install
npx skills add https://github.com/fcalell/dotfiles --skill vitest-fcalell
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/fcalell/dotfiles/tree/main/dot_claude/skills/vitest
Command: npx skills add https://github.com/fcalell/dotfiles --skill vitest-fcalell

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing robust tests for functions, API handlers, and React hooks can be verbose and brittle; Vitest provides fast, modern testing for JavaScript/TypeScript projects to keep code reliable.

Core Features & Use Cases

  • Co-located unit tests next to source files (e.g., src/utils/calculate.ts → src/utils/calculate.test.ts) for easy discovery.
  • Support for integration and API testing patterns, including mock environments and snapshot-friendly outputs.
  • React hook testing with lightweight utilities (e.g., testing-library) and Vitest-compatible async patterns.

Quick Start

Install Vitest in your project and run tests to verify unit and integration logic.

Frequently Asked Questions about vitest

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

FAQPage Schema
How do I write unit tests for TypeScript functions using Vitest?

Unit tests for TypeScript functions using Vitest are written as co-located files next to source code, such as placing calculate.test.ts directly beside calculate.ts, to verify logic quickly and reliably.

Can I test React hooks with Vitest and testing-library?

Testing React hooks with Vitest is fully supported by utilizing lightweight utilities like testing-library alongside Vitest-compatible async patterns to validate hook behavior and state changes.

What is the best way to mock external dependencies for integration tests in Vitest?

The best way to mock external dependencies for integration tests in Vitest is by configuring mock environments within the test runner to isolate API handlers and produce snapshot-friendly outputs.

Does Vitest require a specific project structure for co-located tests?

Vitest requires a project structure that places tests next to source files, meaning your test files should sit directly alongside the modules they verify within your TypeScript project directories.

How do API handler tests work with Vitest in a TypeScript project?

API handler tests with Vitest work by mocking external dependencies within integration test patterns to validate request processing and response logic across your TypeScript project endpoints.