CodePark/ questions / Testing Library queries
START PRACTICINGPRACTICE
Frontend question · Testing › Testing Library queries

According to the Testing Library docs, which list is in priority order, most preferred first?

getByRole, getByLabelText, getByText, getByTestId

The right order is role, label, text, then test id. Queries that match how users and assistive technology find elements come first: role, then label, then placeholder and text. getByTestId is the last resort. Users can't see test ids, so a test id gives no confidence about accessibility. That is why every option that puts getByTestId early is wrong.