Skip to content

Request to add more practical example to the document query page #563

@m98

Description

@m98

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions