-
Notifications
You must be signed in to change notification settings - Fork 470
ByText finds children of hidden elements #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can I take this issue? |
Thanks for the report. Note |
@eps1lon So do you think we should push this one forwards or not? You've added the |
I just don't see why you'd want to use |
Thanks for the feedback but we're not going to implement this.
Before, people would need to know whether a query considers a11y tree inclusion or not. Now they would also need to know how a11y tree inclusion is computed depending on the query. |
It is not always possible to use the
The first one with I would expect that |
@mancristiana how did you end up solving your scenario? I'm running into a similar situation and ended up here. |
One workaround is using a custom TextMatch function.
We can explicitly match elements with TEXT content that don't have an |
You can also use |
@testing-library/react
version: 11.1.0I am using the built-in testing tools that come with
create-react-app
@testing-library/jest-dom
: 5.11.4@testing-library/user-event
: 12.1.10react-scripts
: 4.0.3jest
: 26.6.0 (hoisted fromreact-scripts
)jsdom
: 16.4.0Relevant code or config:
Consider this collapsible element with aria-hidden attribute that displays children props
This assertion fails
What you did:
When using
screen.queryByText("children")
I expected not to find hidden elements that specifyaria-hidden={isCollapsed}
attribute.However, when running the test I could see that the element was found.
What happened:
I got the following failed test:
Reproduction:
I reproduced this issue in this repo: https://github.com/mancristiana/dom-testing-library-template
Problem description:
Since the
findByRole
query supports this scenario, I expected this would be true for other queries.The current behavior is a problem because it does not reflect the way a user would interact with our application. In this concrete example, a hidden element would not appear for the user, whereas our test finds it in the dom tree.
Suggested solution:
Seeing how this behavior is supported for
ByRole
queries I suggest implementing something similar forByText
query.The text was updated successfully, but these errors were encountered: