Question · JavaScript and React course · Module 13: Testing React

RTL selector priority

Which query is the BEST practice according to React Testing Library?

Answer options

  • getByRole - because it reflects how users perceive the elements
  • getByClassName - because it matches the CSS styles
  • getById - because every element should have a unique ID
  • getByTestId - because it is the most precise

You can check the correct answer by solving this task in the CodeWorlds game.