-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
@testing-library/react
version: 16.3.0- Testing Framework and version: jest 30.0.5
- DOM Environment: jest-environment-jsdom 30.0.5
Relevant code or config:
<figure>
<figcaption>Foo</figcaption>
<ul>
<li>Bar</li>
</ul>
</figure>
What you did:
What trying to get hold of the figure element using:
const figure = screen.getByRole("figure", { name: "Foo" });
or
const figure = screen.getByRole("figure", { description: "Foo" });
or
const figure = screen.getByRole("figure", { name: /Foo/ });
or
const figure = screen.getByRole("figure", { description: /Foo/ });
What happened:
ShadowDOMTestingLibraryElementError: Unable to find an element with the role of: figure
Reproduction:
Problem description:
Unable to get figure using accessible name / description in figcaption
As per:
https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/
Like with table elements, if a figure is not named using aria-label or aria-labelledby, the content of the figcaption element will be used as the accessible name. However unlike table elements, if the figcaption element is not used for the name, it does not become an accessible description unless it is referenced by aria-describedby. Nevertheless, assistive technologies will render the content of a figcaption regardless of whether it is used as a name, description, or neither.