agentsclimarketplace

Testing library

Skill G1Joshi/Agent-Skills/skills/testing/testing-library

Testing Library user-centric testing. Use for React testing.From its SKILL.md

Install
npx -y skills add G1Joshi/Agent-Skills --skill testing-library

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 10 stars10 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.0 KB, 456 tokens by cl100k_base, as published. Nobody here has run it

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

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).

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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,871. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.