Best use case
testing-library is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Testing Library user-centric testing. Use for React testing.
Teams using testing-library should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/testing-library/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How testing-library Compares
| Feature / Agent | testing-library | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Testing Library user-centric testing. Use for React testing.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Testing Library (React/DOM)
The guiding principle: **"The more your tests resemble the way your software is used, the more confidence they can give you."**
It encourages testing _behavior_ (what the user sees) rather than implementation details (state, props).
## When to Use
- **React Components**: The industry standard (`@testing-library/react`).
- **Accessibility Testing**: It inherently encourages accessible code (`getByRole`).
## Quick Start
```javascript
import { render, screen, fireEvent } from "@testing-library/react";
import App from "./App";
test("renders learn react link", () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
test("button click", () => {
render(<Button />);
const btn = screen.getByRole("button", { name: /submit/i });
fireEvent.click(btn);
expect(btn).toBeDisabled();
});
```
## Core Concepts
### Queries (Priority)
1. `getByRole`: Best. Tests accessibility structure (button, heading).
2. `getByLabelText`: Good for forms.
3. `getByText`: Good for verifying content.
4. `getByTestId`: **Last Resort**. Only use if nothing else targets the element stable.
### User Event
`fireEvent` is low level. Use `@testing-library/user-event` to simulate real interactions (typing, hovering).
```javascript
import userEvent from "@testing-library/user-event";
await userEvent.click(screen.getByRole("button"));
```
## Best Practices (2025)
**Do**:
- **Use `screen`**: Always import `screen` for global queries.
- **Use `await findBy...`**: For async elements (fetching data). `getBy` fails immediately if not found.
- **Test User Flows**: Don't test valid state; test "User clicks button -> Text appears".
**Don't**:
- **Don't use `container.querySelector`**: Defeats the purpose.
- **Don't test implementation**: Don't check the component's state or class methods directly.
## References
- [Testing Library Docs](https://testing-library.com/)Related Skills
template
Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].
zsh
Zsh shell with oh-my-zsh. Use for terminal shell.
zed
Zed high-performance collaborative editor. Use for fast editing.
xcode
Xcode Apple development IDE with simulators. Use for iOS/macOS development.
webstorm
WebStorm JavaScript IDE with debugging. Use for web development.
webpack
Webpack module bundler with loaders and plugins. Use for bundling.
warp
Warp modern terminal with AI. Use for terminal work.
vscode
Visual Studio Code editor with extensions and debugging. Use for code editing.
vite
Vite fast build tool with HMR. Use for modern frontend builds.
visual-studio
Visual Studio IDE for Windows with debugging and profiling. Use for .NET development.
vim
Vim text editor with motions, macros, and plugins. Use for terminal editing.
turbopack
Turbopack Rust-powered bundler. Use for fast builds.