React Testing Library (RTL) tests components the way users use them: find elements by role, label or text, interact, and assert on what is rendered — not on internal state. Toolchain Tool Role Vitest or Jest test runner & assertions @testing-library/react render components, query the DOM @testing-library/user-event realistic typing/clicking @testing-library/jest-dom matchers like toBeInTheDocument MSW (Mock Service Worker) mock network requests Query priority getByRole("button", { name: /save/i }) — accessible queries first getByLabelText, getByPlaceholderText, getByText getByTestId — last resort Use findBy… (async) for elements that appear later, and queryBy… when asserting something is absent.
Key Takeaways
Test behaviour users see, not implementation details.
Prefer getByRole and getByLabelText queries.
Use user-event for realistic interactions and findBy for async UI.
Mock the network with MSW instead of mocking fetch everywhere.