writing-tests

Automate Vitest and React Testing Library tests across the AiderDesk codebase.

1.4k|128|Updated Jan 7, 2025
One-click install
npx skills add https://github.com/hotovo/aider-desk --skill writing-tests-hotovo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-tests
Source: https://github.com/hotovo/aider-desk/tree/main/.aider-desk/skills/writing-tests
Command: npx skills add https://github.com/hotovo/aider-desk --skill writing-tests-hotovo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

Creating and maintaining tests for AiderDesk is labor-intensive and error-prone, leading to slow feedback and higher risk of regressions without a cohesive testing strategy.

Core Features & Use Cases

  • Guidance for unit, component, and integration testing using Vitest and React Testing Library.
  • Includes patterns for mocking, context testing, and test organization to improve reliability and maintainability.
  • Use cases include adding coverage to new features, debugging failing tests, and setting up consistent test templates.

Quick Start

Create your first Vitest test file for a utility or component and run the test suite.

Frequently Asked Questions about writing-tests

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

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

Write unit tests for React components by leveraging Vitest and React Testing Library to render components, simulate user interactions, and assert DOM output. This approach provides reliable component testing without needing a full browser environment.

What is the best way to mock APIs and context in Vitest integration tests?

Mock APIs and context in Vitest integration tests using centralized mock factories. These factories simulate API responses and React contexts, ensuring consistent and maintainable test environments across your integration testing flows.

Do I need centralized mock factories to run integration tests with Vitest?

Yes, centralized mock factories are required to simulate APIs, contexts, and user interactions. They ensure consistent and maintainable integration tests by standardizing how external dependencies are mocked across the test suite.

How do I improve test coverage for new features using Vitest?

Improve test coverage for new features by applying consistent test templates and patterns for unit, component, and integration testing with Vitest. This adds coverage systematically and reduces the risk of regressions.

Why are my React Testing Library component tests failing to simulate user interactions?

React Testing Library component tests fail when mock factories do not accurately simulate APIs or contexts. Ensure your centralized mock factories correctly wrap components with required providers and mock asynchronous API responses.

Can I debug failing Vitest tests for integration flows?

Debug failing Vitest tests for integration flows by isolating component interactions and verifying centralized mock factories. The testing strategy targets debugging failing tests to quickly identify issues in integration flows.