Skip to content

OrderNot attempted

Query priority

Order Testing Library queries from MOST to LEAST preferred.

Drag the rows, or use the arrows, to put them in order from first to last.

  1. getByTestId
  2. getByText
  3. getByLabelText
  4. getByRole (with name)
Show answer & explanation

Correct order:

  1. getByRole (with name)
  2. getByLabelText
  3. getByText
  4. getByTestId

Role queries match how assistive technology sees the page, so they double as accessibility checks. Labels come next for form fields, then visible text. Test ids are invisible to users, so they're a last resort.