vitest

Write and configure Vitest unit and integration tests with mocks and coverage.

18|Updated Jul 12, 2023
One-click install
npx skills add https://github.com/jaem1n207/synchronize-tab-scrolling --skill vitest-jaem1n207
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/jaem1n207/synchronize-tab-scrolling/tree/main/.agents/skills/vitest
Command: npx skills add https://github.com/jaem1n207/synchronize-tab-scrolling --skill vitest-jaem1n207

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill streamlines the process of writing, running, and managing unit and integration tests for Vite-based projects, offering a faster and more integrated testing experience compared to traditional runners like Jest.

Core Features & Use Cases

  • Vitest Integration: Seamlessly write tests using Vitest, a Vite-native test runner with a Jest-compatible API.
  • Mocking: Easily mock functions, modules, timers, and system time using vi.fn() and vi.mock().
  • Configuration: Leverage Vite's configuration for aliases, plugins, and transforms within your test setup.
  • Coverage: Generate code coverage reports to ensure test thoroughness.
  • Use Case: Develop and test a new Vue component, ensuring all its props, methods, and emitted events function correctly, with mocked API calls and dependencies.

Quick Start

Write Vitest tests for the provided component, mocking its API calls and asserting its rendering.

Frequently Asked Questions about vitest

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

FAQPage Schema
How do I migrate my Jest tests to a Vite-native test runner?

Vitest mocks functions, modules, timers, and system time using vi.fn() and vi.mock(). This allows you to isolate components and assert rendering while intercepting API calls and external dependencies.

How do I configure mocks and API calls in Vitest?

Vitest mocks functions, modules, timers, and system time using vi.fn() and vi.mock(). This allows you to isolate components and assert rendering while intercepting API calls and external dependencies.

Can I use my existing Vite configuration for unit testing?

Vitest generates code coverage reports to ensure test thoroughness. You can configure coverage settings alongside your test scripts to validate that your unit and integration tests exercise all critical code paths.

How do I set up code coverage reporting with Vitest?

Vitest generates code coverage reports to ensure test thoroughness. You can configure coverage settings alongside your test scripts to validate that your unit and integration tests exercise all critical code paths.

Does Vitest support native ESM out of the box?

Yes, Vitest provides native ESM support out of the box. This eliminates the need for manual transpilation configurations required by traditional runners, streamlining the testing process for modern JavaScript projects.