-
Notifications
You must be signed in to change notification settings - Fork 474
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 queries don't properly support the banner role #997
Comments
This is the error I get from the sandbox: |
@all-contributors add @jrnail23 for bug |
I've put up a pull request to add @jrnail23! 🎉 |
Um, this is awkward... I just ran into the same issue I had when I opened this bug a hundred years ago. Running @testing-library/react@16.2.0, @testing-library/jest-dom@6.6.3 import {render, screen} from '@testing-library/react';
import React from 'react';
test('find by banner role should only return the top-level header', () => {
render(
<React.Fragment>
<header>
<h1>2 Rooms</h1>
</header>
<main>
<ul>
<li>
<header>
<h2>Level 1</h2>
</header>
<h3>Ballroom A</h3>
</li>
<li>
<header>
<h2>Level 2</h2>
</header>
<h3>Ballroom C</h3>
</li>
</ul>
</main>
</React.Fragment>
);
expect(screen.getAllByRole('banner')).toHaveLength(1);
}); still fails like it did back then:
Please reopen this bug. |
@testing-library/dom
version: 7.28.1Testing Framework and version: Jest 26.6.3
DOM Environment: jsdom 16.6
Node: 14.16
What you did:
Given this HTML body:
What happened:
screen.getByRole('banner')
throwsTestingLibraryElementError: Found multiple elements with the role "banner"
Reproduction:
https://codesandbox.io/s/react-testing-library-demo-forked-7rp9f?file=/src/__tests__/hello.js
Problem description:
According to WAI-ARIA:
header
article
,aside
,main
,nav
orsection
element, or an element withrole=article
,complementary
,main
,navigation
orregion
thenrole=banner
. Otherwise no corresponding roleSuggested solution:
the
ByRole
queries should adhere to ARIA specs, and only implicitly assume thebanner
role for<header>
elements when they are not descendants of the specified elementsThe text was updated successfully, but these errors were encountered: