vitest

Write React unit and integration tests with Vitest and React Testing Library.

1|Updated Aug 16, 2025
One-click install
npx skills add https://github.com/professor-moody/cloud-tools --skill vitest-professor-moody
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest
Source: https://github.com/professor-moody/cloud-tools/tree/main/repos/prowler/skills/vitest
Command: npx skills add https://github.com/professor-moody/cloud-tools --skill vitest-professor-moody

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill streamlines the process of writing effective unit and integration tests for React components, hooks, and utilities using the Vitest testing framework and React Testing Library.

Core Features & Use Cases

  • Standardized Testing Patterns: Enforces the Given/When/Then (AAA) structure for clear and maintainable tests.
  • Optimized Querying: Guides users to prioritize accessible DOM queries (getByRole, getByLabelText) over brittle selectors.
  • Interaction Handling: Promotes the use of userEvent for realistic user interaction simulation.
  • Async Testing: Provides patterns for handling asynchronous operations and assertions effectively.
  • Mocking Strategies: Demonstrates best practices for mocking with vi.fn() and vi.spyOn.
  • Use Case: When developing a new form component in React, use this skill to ensure all user interactions like typing and button clicks are correctly tested, and that form submission logic behaves as expected.

Quick Start

Use the vitest skill to write a unit test for the UserProfile component, ensuring it displays the user's name correctly after it's loaded.

Frequently Asked Questions about vitest

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

FAQPage Schema
How do I write React unit tests using Vitest and React Testing Library?

To write React unit tests using Vitest, structure your test cases with the Given/When/Then pattern, use React Testing Library for accessible DOM queries, and simulate user interactions with userEvent to ensure robust component behavior validation.

What is the best way to simulate user interactions in Vitest integration tests?

The best way to simulate user interactions in Vitest integration tests is utilizing the userEvent library to realistically replicate actions like typing and clicking, ensuring your React components respond correctly to actual user behavior.

How should I handle asynchronous operations when testing React components with Vitest?

When testing React components with Vitest, handle asynchronous operations by applying specific assertion patterns provided by the testing framework to effectively wait for and verify dynamic DOM updates and data fetching results.

Does this Vitest testing approach enforce specific DOM query methods for React components?

Yes, this Vitest testing approach requires prioritizing accessible DOM queries such as getByRole and getByLabelText over brittle selectors, ensuring your React component tests remain maintainable and closely mimic accessibility requirements.

What mocking strategies should I use for React testing with Vitest?

For React testing with Vitest, adhere to specific mocking strategies using vi.fn() for creating mock functions and vi.spyOn() for tracking method calls to isolate components and verify interaction logic robustly.