vitest-skill

Generates Vitest unit and component tests for JavaScript and TypeScript projects.

Updated Aug 11, 2026
One-click install
npx skills add https://github.com/DucCuong159/Realtime-chatapp --skill vitest-skill-duccuong159
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest-skill
Source: https://github.com/DucCuong159/Realtime-chatapp/tree/main/.agent/skills/vitest-skill
Command: npx skills add https://github.com/DucCuong159/Realtime-chatapp --skill vitest-skill-duccuong159

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing tests with Vitest requires knowing its Jest-compatible but distinct API (vi.mock, vi.fn, fake timers), configuration options, and patterns like in-source testing, which developers often get wrong by mixing in Jest idioms. ## Core Features & Use Cases - Test Generation Patterns: Provides ready-to-use templates for unit tests, module mocking with vi.mock, spies, fake timers, and snapshot testing. - React Component Testing: Covers Testing Library integration for rendering and asserting on React components in a jsdom environment. - Configuration Guidance: Includes a complete vitest.config.ts setup with coverage, globals, and includeSource for co-located in-source tests. - Use Case: When migrating a Vite-based TypeScript project from Jest, use this Skill to rewrite jest.mock calls as vi.mock, configure vitest.config.ts, and generate table-driven tests with test.each. ## Quick Start Ask the AI to generate Vitest tests with mocking and coverage configuration for a specific TypeScript module in your project.

Frequently Asked Questions about vitest-skill

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

FAQPage Schema
How do I write Vitest tests for TypeScript modules?

Import describe, it, expect, and beforeEach from 'vitest', then structure tests around the module under test. Vitest is TypeScript-first, so typed test files run natively without extra transpilation setup.

How to mock modules in Vitest with vi.mock?

Call vi.mock('./module', () => ({ ... })) at the top of the test file to replace module exports with mock implementations. Use vi.fn().mockResolvedValue() for async functions and vi.spyOn for partial spying on existing objects.

What is the difference between Jest and Vitest APIs?

Vitest uses the vi namespace instead of jest: vi.fn() replaces jest.fn() and vi.mock() replaces jest.mock(). The assertion API remains Jest-compatible, so expect statements and matchers work the same way.

Does Vitest support React component testing?

Yes, Vitest works with @testing-library/react when the environment is set to 'jsdom' in vitest.config.ts. Render components with render() and assert on output using screen queries like getByText.

How do I run Vitest with coverage reports?

Run npx vitest --coverage to generate coverage using the v8 provider configured in vitest.config.ts. Reporters such as text and html can be specified under the coverage.reporter option.

When should I avoid in-source testing in Vitest?

In-source testing via import.meta.vitest co-locates tests in production files, which can bloat bundles if not stripped at build time. Use it for small utility modules, but prefer separate test files for larger suites.