Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

React Testing Library getByRole vs. getByText

getByRole()

  • roles are automatically inferred based on ARIA specs, or they can be manually set
  • it's generally preferred because it's more robust, it mirrors more accurately the UX and it tests accessible elements (accessibility tree)
  • the returned objects can be queried by accessible names
  • it's less performant especially in large DOMs

--

Resources


You'll only receive email when they publish something new.

More from Marcella Malune
All posts