What is React Testing Library?
Answer
React Testing Library (RTL) is the official recommended testing utility for React. Its philosophy: test components the way users interact with them — not implementation details. RTL renders components in a virtual DOM (via jsdom) and provides queries to find elements like a user would: by text, role, label, placeholder — not by class names or component internals. Key queries: getByRole("button", { name: "Submit" }), getByLabelText("Email"), getByText("Welcome"), findByText("Loaded!") (async). Key actions: userEvent.click(button), userEvent.type(input, "hello"). Assertions: with jest-dom: expect(element).toBeInTheDocument(), toHaveValue("hello"), toBeDisabled(). Philosophy benefits: tests do not break when you refactor internals (change class names, extract components) — they only break when behavior changes. This produces more durable, maintainable tests. Avoid: testing component state directly, implementation details, or internal methods. Instead, test what the user sees and can do.
Previous
What is the difference between client-side routing and server-side routing?
Next
How does React's reconciliation algorithm handle keys?