Closed
Description
@testing-library/dom
version:7.5.1
@testing-library/jest-dom
:5.7.0
@testing-library/react
:10.0.4
jest
:24.9.0
Relevant code or config:
import React from "react";
import { render, screen } from "@testing-library/react";
describe("getByRole", () => {
test("doens't consider a <header> as banner role", () => {
render(<header>Test</header>);
expect(screen.getByRole("banner")).toBeInTheDocument();
});
});
What you did:
The header
tag has an implicit banner
role. RTL's getByRole
should be able to identify this.
What happened:
TestingLibraryElementError: Unable to find an accessible element with the role "banner"
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole
<body>
<div>
<header>
Test
</header>
</div>
</body>
Problem description:
From the official W3C specs:
- The HTML
header
element defines abanner
landmark when its context is thebody
element. - The HTML
header
element is not considered abanner
landmark when it is descendant of any of following elements:
article
aside
main
nav
section
Chrome gets this one right:
Suggested solution:
RTL should be able to identify the role correctly with respect to the above banner
specs for the header
tag.