testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.26k stars 466 forks source link

getByRole not finding Element by implicit role #1201

Closed joshua-rh closed 5 months ago

joshua-rh commented 1 year ago

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

timdeschryver commented 1 year ago

This should be available in the next version of aria-query. The fix was committed in this PR https://github.com/A11yance/aria-query/pull/447 (updated the relatedConcepts of the button role)

samirergaibi commented 9 months ago

When is the deployment scheduled for this? Currently facing a similar issue in react-testing-library not being able to select strong elements by their implicit role.

MatanBobi commented 8 months ago

@samirergaibi - DTL 10 was released in our alpha channel, you can give it a try. We still want to run it in some wider codebases before releasing it. If you can give it a try in your repo by using overrides and provide inputs it can be amazing.

MatanBobi commented 5 months ago

:tada: This issue has been resolved in version 10.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: