accelint-react-testing

Guide React component tests with Testing Library queries and userEvent interactions.

22|12|Updated May 29, 2024
One-click install
npx skills add https://github.com/gohypergiant/standard-toolkit --skill accelint-react-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: accelint-react-testing
Source: https://github.com/gohypergiant/standard-toolkit/tree/main/.agents/skills/accelint-react-testing
Command: npx skills add https://github.com/gohypergiant/standard-toolkit --skill accelint-react-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill helps you write more robust, accessible, and maintainable React component tests using Testing Library, preventing common pitfalls and ensuring your tests accurately reflect user behavior.

Core Features & Use Cases

  • Accessible Querying: Guides you to use semantic queries (role, label) over brittle test IDs.
  • Realistic Interactions: Promotes userEvent over fireEvent for accurate user simulation.
  • Async Handling: Provides patterns for managing asynchronous operations and avoiding race conditions.
  • Use Case: When writing tests for a new React component, this Skill ensures you're using the best practices for querying elements, simulating user interactions, and handling asynchronous updates, leading to tests that are less likely to break during refactoring and more confident in their coverage.

Quick Start

Use the accelint-react-testing skill to review the test file 'src/components/Button.test.tsx' for best practices.

Frequently Asked Questions about accelint-react-testing

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

FAQPage Schema
How do I write better React component tests using Testing Library?

React component tests should prioritize accessible queries like getByRole over test IDs to ensure robustness. Simulate user interactions with userEvent, handle asynchronous updates using waitFor or findBy, and wrap custom render setups with providers to accurately reflect user behavior.

What is the query priority hierarchy in React Testing Library?

React Testing Library prioritizes semantic and accessible queries like getByRole and getByLabelText over test IDs or DOM container structure, ensuring tests validate accessibility and reflect actual user behavior and interactions.

Should I use userEvent or fireEvent for React testing interactions?

Use userEvent instead of fireEvent for React testing interactions because userEvent simulates realistic browser behavior more accurately, matching actual user-centric interaction patterns and preventing common testing pitfalls.

How do I handle asynchronous operations in React component tests?

Handle asynchronous operations in React component tests by using findBy queries to await elements, waitFor to assert repeated conditions, and queryBy to check absence, preventing race conditions and ensuring accurate async testing coverage.

Does this React testing approach work with custom render setups and providers?

Yes, this React testing approach supports custom render setups with providers, allowing you to wrap components with necessary context providers and apply accessibility-first assertions like toBeInTheDocument alongside jest-dom for comprehensive testing.