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 467 forks source link

ByRole doesn't find SVG's graphics-document role #1131

Closed CreativeTechGuy closed 2 years ago

CreativeTechGuy commented 2 years ago

Relevant code or config:

getByRole("graphics-document")

What you did:

I have an SVG element in the page which I'm trying to select by its role.

What happened:

In the W3 role documentation linked from the ByRole docs, it lists the implicit role for an SVG tag as graphics-document. This value isn't included in the TypeScript definitions, but more importantly it isn't supported at runtime either.

Reproduction:

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

Problem description:

The only way to query for an SVG is via querySelector which goes against the recommendations of the library.

Suggested solution:

Support the aria-role as a selector as the documentation would suggest is possible.

timdeschryver commented 2 years ago

This will land when https://github.com/A11yance/aria-query/issues/181 is resolved.

mmarcuccio commented 1 year ago

It looks like the update to aria-query did not resolve this. Here is an updated version of the sandbox above: https://codesandbox.io/s/react-testing-library-demo-forked-221xzs?file=/src/__tests__/hello.js

freedude commented 4 months ago

its May 1st 2024 and I am still seeing the same issue, was this ever resolved or did anyone find another way?