testing-library / testing-library/react-testing-library

Unable to getByRole figure with accessible name / description in figcaption

Open
#1,417 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
19.7k
Forks
1.2k
Avg merge
3d 16h
Merged PRs (30d)
1

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported figure markup with screen.getByRole using the accessible name and description options. Trace the getByRole handling for figure and figcaption semantics, then verify that the query finds the figure with the expected accessible name or description.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.