Skip to content

getByRole doesn't work for menu with aria-label #1078

Closed
@sandrina-p

Description

@sandrina-p
  • @testing-library/dom version: 4.1.0
  • Testing Framework and version: Jest (The same as in the codesandbox below)

Relevant code or config:

    <ul role="menu" aria-label="actions">
      <li role="menuitem">copy</li>
      <li role="menuitem">paste</li>
      <li role="menuitem">cut</li>
    </ul>
    
    <ul role="menu" aria-label="share">
      <li role="menuitem">copy link</li>
      <li role="menuitem">report bug</li>
    </ul>

What you did:

screen.getByRole('menu', { name: 'actions' }) 

What happened:

The element was not found.

Unable to find an accessible element with the role "menu" and name "actions"

I was expecting to be found because, according to the Chrome's Accessibility Tree, the role and name are set correctly:

image

Reproduction:

References:

This was originally discovered at Discord KCD by Thomas.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions