r/learnreactjs • • May 06 '22

React Testing Library - what does "Queries Accessible by Everyone" mean?

I keep seeing that as the title of a major section of queries.

What does it mean? Why would you want your testing "accessible to everyone"? You or the other developers are the only ones who are gonna see the tests so I don't understand the perspective.

The other section titles are:

Semantic Queries

and

Test IDs

What section allows me to just pick the element I want to test and test it? Like grab a input field or an img tag or something along those lines? I don't understand the language. Does "accessible by everyone" just mean "anything on the website anyone can see"?

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/BilboMcDoogle May 07 '22

So what's the difference with Semantic Queries and Test IDs?

Are they for backend stuff?

1

u/Izero_devI May 08 '22

No, no. It is all frontend, this is React we are talking about. Queries are for tests to target elements on the DOM.

So library just want to tell you that if you are going to target/query an element

  • first try to do it by using accessiblity features, if not possible, then,
  • use semantically correct features, if that is also not possible then,
  • use test ids.

1

u/BilboMcDoogle May 08 '22

Oh I see. Thank you now I get it lol.