-
Notifications
You must be signed in to change notification settings - Fork 466
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
*ByRole reads hidden element names as "" #846
Comments
I lean towards leaving this as undefined behavior. Since the accessible name is affected by styling, ignoring it leaves you in an awkward spot. It makes sense in this specific case but the code is going to be really hairy getting all the edge cases right if the element isn't actually part of the a11y tree. For example what happens if you use
I would recommend testing under these circumstances. Then you also make sure that your assumptions are actually correct. |
That would be my preference too, but I don't think I can make that happen without moving our whole test infrastructure to Cypress (or something else–jsdom appears to ignore media queries). The only work-around within Testing Library I'm aware of is to switch to a less semantically meaningful query which feels like a lot to sacrifice just because our mobile layout has changed. I do see your point about the room for edge cases here. Maybe the best fix for my scenario is to patch |
I'm having similar issues, but in my case it was Example: // pseudo code of the component to test
const Carousel = () => {
return (
<ul>
<li aria-hidden="false">Slide 1</li>
<li aria-hidden="true">Slide 2</li>
</ul>
)
} // sample test
render(<Carousel />);
expect(screen.getAllByRole('listitem', { name: /Slide/, hidden: true }).toHaveLength(3); This test will fail with similar message as the OP. I "think" it was because the I noticed that it also checks for |
I am having a similar issue, where I have two button elements and one is hidden. I cannot use getByRole with 'hidden = true', because the library is complaining that it found two elements with the same role. As stated above, a hidden element does not have a name. So tried to use Why do I get this warning with |
I'm facing similar issue. I want to find a display value of a textbox but getting multiple results Example code:
Test Query:
and the error i'm getting:
in my expectation displayed value are the elements in the DOM with visibility Packages Detail: |
I'm facing similar issue. I have a menu bar that turns into hamburger on mobile devices and my tests are failing when using |
Sorry, I had a similar problem and I was wondering if this problem was solved. I tried to filter the results with hidden: true, but getAllByRole returns me all the roles example code for unit code example code for dom In my expectation, this should return that element corresponding to the aria attribute under this role instead of throwing it all to me If anyone can help me with this problem, it would be really appreciated! |
@testing-library/dom
version: 7.28.1Relevant code or config:
What you did:
Attempted to test the presence of accessible elements with
display: none;
What happened:
The Testing Library error reporter claims the name of these elements is
""
and fails to match them against the provided name:Reproduction:
Hopefully the provided code is sufficient, let me know if not
Problem description:
The example I've given is a little simplified–the real code I'm testing contains elements that are visible in desktop-width viewports, and if I understand correctly media query parsing is out-of-scope for Testing Library–but the issue is the same: these elements will become part of the accessibility tree under certain circumstances and I'm ignoring their invisibility in order to check that they have the correct accessible names. I would expect that I'd be able to do that with the
hidden: true
option set.Suggested solution:
I don't have the time to spare to figure out the cause of this right now :( it might be related to recent changes around #804 ?
The text was updated successfully, but these errors were encountered: