Skip to content

getByRole not finding Element by implicit role #1201

Closed
@joshua-rh

Description

@joshua-rh
  • @testing-library/dom version: 16.9
  • Testing Framework and version: 9.2
  • DOM Environment: 4.1.0

See codesandbox

Relevant code or config:

test("getByRole", () => {
  render(
    <div>
      <strong>hello</strong>
    </div>
  );
  screen.getByRole("strong"); // errors
});

What you did:

What happened:

Unable to find an accessible element with the role "strong"

Here are the accessible roles:

  document:

  Name "":
  <body />

  --------------------------------------------------

<body>
  <div>
    <div>
      <strong>
        hello
      </strong>
    </div>
  </div>
</body>

Reproduction:

https://codesandbox.io/s/react-testing-library-demo-forked-lzjrl1?file=/src/__tests__/getByRole.js

Problem description:

According to https://testing-library.com/docs/queries/byrole/, we should use the HTMLElement's role. According to this table, <strong> has an implicit role of strong but it does not get found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions