-
Notifications
You must be signed in to change notification settings - Fork 726
Description
I know the whole point of this testing library is to do testing "how a user would" and "how user see".
But imagine the time that we have multiple headlines on our page (ex, h2, h3, h4), h2 holds the product name, and h3 holds the product manufacturer. Just by getAllByRole('heading')
we can't exactly address the specific tag we need to test (ex, product name), there is a need to exactly address which "heading" do we mean. I'm sure there are several good ways to React Testing Library to solve this problem easily, but the documentation is a problem. I saw many StackOverflow questions about the getByRole
, and many user are even writing "role" even when it's not necessary. On the other hand, accessing by "getByRole" is not that clear for developers who used to work with Enzyme (and JQuery API)
When you look at the documentation, most of the examples are about images, input, label, and button. For edge cases like the example I provided (multiple headlines, how to address each exactly) does not have a good practical example there. Or what if there are several div, and user needs to access one (I mean without using data-testid
, which is this library's main focus as long as possible)
The documentation page need some polishing and re-writing, and I would be glad to help