Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getByRole not finding Element by implicit role #1201

Closed
joshua-rh opened this issue Jan 6, 2023 · 4 comments · Fixed by #1241
Closed

getByRole not finding Element by implicit role #1201

joshua-rh opened this issue Jan 6, 2023 · 4 comments · Fixed by #1241

Comments

@joshua-rh
Copy link

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

@timdeschryver
Copy link
Member

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

@samirergaibi
Copy link

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
Copy link
Member

@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
Copy link
Member

🎉 This issue has been resolved in version 10.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants