Skip to content

React Testing Library

import { rtl } from "testing-widgets/adapters/rtl";
function rtl(container?: HTMLElement, user?: UserEventLike): Locator;
  • container — root element to query within (defaults to document.body)
  • user — optional userEvent instance for realistic interactions
import { render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { rtl } from "testing-widgets/adapters/rtl";
const user = userEvent.setup();
const { container } = render(<MyComponent />);
const locator = rtl(container, user);
const { elements, actions } = myWidget.from(locator);

When user is provided, click(), fill(), clear(), and selectOption() delegate to userEvent for realistic browser behavior. Without it, the adapter falls back to native DOM methods.

The adapter has its own lightweight DOM query engine — no @testing-library/dom dependency. It supports these implicit role mappings:

RoleSelectors
buttonbutton, [role="button"], input[type="button"|"submit"]
textboxinput (no type / type="text"), textarea, [role="textbox"]
checkboxinput[type="checkbox"], [role="checkbox"]
radioinput[type="radio"], [role="radio"]
linka[href], [role="link"]
headingh1–h6, [role="heading"]
listul, ol, [role="list"]
listitemli, [role="listitem"]
comboboxselect, [role="combobox"]
dialogdialog, [role="dialog"]
imgimg[alt], [role="img"]

Other roles fall back to [role="..."]. Name matching checks aria-label then text content.