Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Unable to getByRole figure with accessible name / description in figcaption

Aperta
#1,417 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, react
Ambito
testing

Direzione di ricerca

Inizia riproducendo il markup di figure segnalato con screen.getByRole usando le opzioni accessible name e description. Segui quindi la gestione della semantica di figure e figcaption da parte di getByRole, poi verifica che la query trovi il figure con l’accessible name o la description prevista.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

  • @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.

Lingua principale
JavaScript
Stelle
19.7k
Fork
1.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testing-library/react-testing-library

Tutte le issue di testing-library/react-testing-library

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.