
React Testing Library
Give your agent a concise React Testing Library API reference while writing or fixing component tests with render, screen queries, and provider wrappers.
Overview
React Testing Library is an agent skill most often used in Ship (also Build frontend) that documents render(), screen queries, and render options for user-centric React component tests.
Install
npx skills add https://github.com/itechmeat/llm-code --skill react-testing-libraryWhat is this skill?
- render() signature with container, wrapper, hydrate, and custom queries options
- Documented render options table for baseElement, legacyRoot, and reactStrictMode
- React 19 onCaughtError and onRecoverableError hooks in render options
- screen.getByText-style queries in minimal component test examples
- Provider wrapper pattern for integrated component trees under test
- Render options table documents 8+ core render() configuration fields
Adoption & trust: 947 installs on skills.sh; 17 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are writing React component tests and need correct render options, query imports, and React 19 nuances without spelunking the full docs mid-task.
Who is it for?
Solo builders shipping React or React 19 apps who want fast, accurate RTL API reminders while pairing with Jest or Vitest.
Skip if: Teams standardizing on Enzyme-only snapshots, pure E2E Playwright coverage with no component tests, or non-React UI frameworks.
When should I use this skill?
Writing or updating React component tests with @testing-library/react render and screen queries
What do I get? / Deliverables
Your agent emits RTL tests that render with the right wrapper and options and assert through screen queries aligned with Testing Library conventions.
- Component test files using render and screen assertions
- Provider wrapper setup for integrated RTL suites
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Ship/testing is canonical because the skill is centered on verification behavior—asserting UI outcomes—not on initial UI design. Testing subphase matches render/screen patterns, query usage, and React 19 error-handler options that gate release confidence.
Where it fits
Scaffold a new Greeting component test with render and screen.getByText before merging the UI PR.
Add a wrapper with shared providers so integration-style RTL tests match production context.
Verify an agent’s test patch uses supported render options instead of deprecated legacyRoot on React 19.
Extend regression tests after a production UI bug using documented query and render patterns.
How it compares
Use this RTL reference skill instead of generic “write unit tests” prompts that ignore render wrappers and user-facing queries.
Common Questions / FAQ
Who is react-testing-library for?
It is for indie React developers and agent-assisted coders who need a tight API reference for @testing-library/react while authoring or refactoring component tests.
When should I use react-testing-library?
Use it during Ship testing when adding render/screen specs, configuring providers via wrapper, or handling React 19 error options; also during Build frontend when scaffolding tests alongside new components.
Is react-testing-library safe to install?
It is read-only reference documentation without shell or network side effects; still review the Security Audits panel on this Prism page before adding any skill repo to your agent environment.
SKILL.md
READMESKILL.md - React Testing Library
# React Testing Library API Reference ## render() ```ts import { render } from '@testing-library/react' const result = render(ui, options?) ``` ### Basic Usage ```tsx import { render, screen } from "@testing-library/react"; test("renders greeting", () => { render(<Greeting name="World" />); expect(screen.getByText("Hello, World!")).toBeInTheDocument(); }); ``` ### Render Options ```ts render(<Component />, { container: document.body.appendChild(document.createElement("div")), baseElement: document.body, hydrate: false, legacyRoot: false, // React 17 mode (not available in React 19+) wrapper: AllProviders, queries: { ...queries, ...customQueries }, reactStrictMode: true, // React 19 error handlers onCaughtError: (error, errorInfo) => {}, onRecoverableError: (error, errorInfo) => {}, }); ``` | Option | Description | | -------------------- | ------------------------------------------------ | | `container` | DOM element to render into | | `baseElement` | Element for queries (default: document.body) | | `hydrate` | Use ReactDOM.hydrate for SSR | | `legacyRoot` | Use React 17 rendering (not in React 19+) | | `wrapper` | Component to wrap around rendered element | | `queries` | Custom queries to use | | `reactStrictMode` | Enable React StrictMode | | `onCaughtError` | Callback for errors caught by Error Boundary | | `onRecoverableError` | Callback for errors React automatically recovers | ### Render Result ```ts const { container, // DOM container element baseElement, // Base element for queries debug, // console.log(prettyDOM()) rerender, // Re-render with new props unmount, // Unmount component asFragment, // Get DocumentFragment snapshot ...queries // All query functions bound to baseElement } = render(<Component />); ``` ### React Error Handlers (v16.2.0+) Handle errors in tests with React 19 error callbacks: ```tsx test("catches error boundary errors", () => { const errors: Error[] = []; render(<ComponentWithErrorBoundary />, { onCaughtError: (error, errorInfo) => { errors.push(error); console.log("Caught:", error.message); console.log("Component stack:", errorInfo.componentStack); }, }); // Trigger error and verify fireEvent.click(screen.getByRole("button", { name: /throw/i })); expect(errors).toHaveLength(1); }); test("handles recoverable errors", () => { const recoverableErrors: Error[] = []; render(<HydratedComponent />, { hydrate: true, onRecoverableError: (error, errorInfo) => { recoverableErrors.push(error); }, }); expect(recoverableErrors).toHaveLength(0); }); ``` --- ## screen Pre-bound queries for document.body: ```ts import { render, screen } from "@testing-library/react"; render(<Component />); // All queries available screen.getByRole("button"); screen.queryByText("Loading"); screen.findByLabelText("Email"); // Debug screen.debug(); screen.debug(screen.getByRole("button")); // Playground URL screen.logTestingPlaygroundURL(); ``` --- ## rerender() Update props without remounting: ```tsx const { rerender } = render(<Counter count={1} />); expect(screen.getByText("Count: 1")).toBeInTheDocument(); rerender(<Counter count={2} />); expect(screen.getByText("Count: 2")).toBeInTheDocument(); ``` --- ## unmount() ```ts const { unmount } = render(<Component />); unmount(); // Component is now unmounted, container is empty ``` --- ## asFragment() Create snapshot of current DOM state: ```tsx const { asFragment } = render(<Component />); const firstRender = asFragment(); fireEvent.click(screen.getByRole("button")); // Snapshot diff expect(firstRender).toMatchDiffSnapshot(asFragment()); ``` --- ## cleanup() Unmounts all rendered components. Called automaticall