react-testing-library

React Testing Library: user-centric component testing with queries, user-event simulation, async utilities, and accessibility-first API. Use when writing React component tests, selecting elements by role/label/text, simulating user events, or testing async UI behavior. Keywords: React Testing Librar

By itechmeat · 1,324 installs

npx skills add itechmeat/llm-code --skill react-testing-library

Source repository · Upstream listing

React Testing Library Skill Quick Navigation Topic Link Queries [references/queries.md](references/queries.md) User Events [references/user events.md](references/user events.md) API [references/api.md](references/api.md) Async [references/async.md](references/async.md) Debugging [references/debugging.md](references/debugging.md) Config [references/config.md](references/config.md) Installation Install: npm install save dev @testing library/react @testing library/dom . Recommended extras: @testing library/user event and @testing library/jest dom . React 19 requires v16.1.0+. Core Philosophy "The more your tests resemble the way your software is used, the more confidence they can give you." Avoid testing : Internal state of components Internal methods Lifecycle methods Child component implementation details Test instead : What users see and interact with Behavior from user's perspective Accessibility (queries by role, label) Query Priority Use queries in this order of preference: 1. Accessible to Everyone (Preferred) 2. Semantic Queries 3. Test IDs (Escape Hatch) Query Types Type No Match 1 Match 1 Match Async getBy... throw return throw No queryBy... null return throw No findBy... throw return throw Yes getAllBy... throw array array No queryAllBy... [] array array No findAllBy... throw array array Yes When to use : getBy — element exists queryBy — element may not exist (assertions like expect(...).not.toBeInTheDocument() ) findBy — element appears asynchronously Basic Test Pattern User Events Always use @testing library/user event over fireEvent : Async Patterns waitFor — Retry Until Success findBy — Built in waitFor waitForElementToBeRemoved Common Patterns Custom Render with Providers Testing Hooks Rerender with New Props Query Within Container Debugging jest dom Matchers Configuration ❌ Prohibitions (Anti patterns) ✅ Best Practices TextMatch Options Quick Reference Import Usage render Render component to DOM screen Query the rendered DOM cleanup Unmount components (auto in Jest) act Wrap state updates renderHook Test custom hooks within Scope queries to element waitFor Retry until assertion passes configure Set global options userEvent.setup() Create user event instance Links [Documentation](https://testing library.com/docs/react testing library/intro/) [Releases](https://github.com/testing library/react testing library/releases) [GitHub](https://github.com/testing library/react testing library) [npm](https://www.npmjs.com/package/@testing library/react)