vitest-testing

Write and run unit and integration tests for TypeScript and JavaScript projects with Vitest.

4|Updated May 13, 2026
One-click install
npx skills add https://github.com/RuixeWolf/modbus-simulator --skill vitest-testing-ruixewolf
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: vitest-testing
Source: https://github.com/RuixeWolf/modbus-simulator/tree/main/.agents/skills/vitest-testing
Command: npx skills add https://github.com/RuixeWolf/modbus-simulator --skill vitest-testing-ruixewolf

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires vitest, supertest.

What problem does it solve? Setting up and writing tests for TypeScript/JavaScript projects often involves slow tooling, complex configuration, and inconsistent mocking patterns. This Skill provides ready-to-use Vitest knowledge so you can configure, write, run, and measure tests without digging through documentation. ## Core Features & Use Cases - Test Authoring: Covers describe/it structure, parametrized tests with describe.each, and a full assertion reference including promises and exceptions. - Mocking & Timers: Provides patterns for function mocks, module mocking with vi.mock, fake timers, and system time control. - Coverage & Integration Testing: Shows how to generate coverage reports with thresholds and test HTTP APIs using supertest. - Use Case: You just added a new utility module to your TypeScript project. Use this Skill to scaffold a matching test file, mock its external API dependency, and run the suite with coverage thresholds enforced in CI. ## Quick Start Ask the AI to set up Vitest in your project and write unit tests with mocks and coverage for a specified source file.

Frequently Asked Questions about vitest-testing

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

FAQPage Schema
How do I write unit tests with Vitest?▼

Import describe, it, and expect from vitest, group related cases in describe blocks, and assert results with matchers like toBe, toEqual, and toThrow. Run tests with bun test or vitest run for CI mode.

How to mock modules and functions in Vitest?▼

Use vi.fn() for function mocks with mockReturnValue or mockResolvedValue, and vi.mock('./module', factory) to replace entire modules. Call vi.clearAllMocks() in beforeEach to reset state between tests.

Does Vitest support fake timers and date mocking?▼

Yes. Enable vi.useFakeTimers(), then use vi.advanceTimersByTime() to fast-forward setTimeout callbacks and vi.setSystemTime() to freeze Date.now() at a specific timestamp.

How do I check test coverage in Vitest?▼

Run tests with the --coverage flag using the v8 provider to generate text, JSON, or HTML reports. You can enforce minimum thresholds for lines, functions, and branches directly in vitest.config.ts.

Can Vitest test Express or HTTP API endpoints?▼

Yes, combine Vitest with supertest to send HTTP requests against your app instance and assert on status codes and response bodies. This works for integration testing without starting a real server.