Loading...
Loading...
Use when writing, fixing, editing, or refactoring React tests with Testing Library, user-event, component rendering, accessibility queries, async UI, mocks, brittle fixtures, test data builders, or behavior coverage.
npx skill4agent add gosukiwi/clean-code-react clean-react-testsgetByRolegetByLabelTextgetByTextgetByTestId// Bad - coupled to markup
expect(container.querySelector(".save-button")).toBeTruthy();
// Good - coupled to user-visible behavior
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();userEventfireEventconst user = userEvent.setup();
await user.type(screen.getByLabelText("Email"), "ada@example.com");
await user.click(screen.getByRole("button", { name: "Invite" }));
expect(await screen.findByText("Invitation sent")).toBeInTheDocument();display: griddisplay: flex// Bad - locks in an incidental layout implementation
expect(screen.getByTestId("actions")).toHaveStyle({ display: "grid" });
// Good - checks the behavior the layout supports
expect(screen.getByRole("button", { name: "Save" })).toBeVisible();
expect(screen.getByRole("button", { name: "Cancel" })).toBeVisible();findBy...waitFor// Bad - fixture noise hides the state being tested
render(<OrderSummary order={{ id: "1", status: "paid", lineItems: [], discounts: [] }} />);
// Good - the relevant state is the visible part
render(<OrderSummary order={buildOrder({ status: "paid" })} />);