Skip to content

LocatorWith

LocatorWith extends Locator with convenience methods. This is the type you get inside a widget() factory.

import type { LocatorWith } from "testing-widgets";

Drop the getBy prefix:

AliasEquivalent
byRole(role, opts?)getByRole(role, opts?)
byLabel(text)getByLabel(text)
byPlaceholder(text)getByPlaceholder(text)
byText(text)getByText(text)
byTestId(id)getByTestId(id)

Call getByRole() with a preset role. All return LocatorWith for chaining.

MethodRoleExtra options
button()buttonname
link()linkname
textbox()textboxname
checkbox()checkboxname, checked
radio()radioname, checked
combobox()comboboxname
heading()headingname
dialog()dialogname
list()listname
listitem()listitemname
img()imgname
tab()tabname, selected
tabpanel()tabpanelname
navigation()navigationname
region()regionname

Shortcuts chain naturally:

l.dialog({ name: "Confirm" }).button({ name: "OK" })