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('meter') doesn't find meter element #1171

Closed
idanen opened this issue Sep 19, 2022 · 8 comments
Closed

getByRole('meter') doesn't find meter element #1171

idanen opened this issue Sep 19, 2022 · 8 comments

Comments

@idanen
Copy link
Collaborator

idanen commented Sep 19, 2022

  • @testing-library/dom version: ^8.17.0
  • Testing Framework and version: jest ^28.1.0
  • DOM Environment: In codesandbox

Relevant code or config:

test('getting by implicit "meter" role', () => {
  const aValue = 21;
  render(<Meter value={aValue} />);
  expect(screen.getByRole("meter")).toHaveValue(aValue);
});

function Meter({
  value = 0,
  min = 0,
  max = 0,
  low = 3,
  high = 90,
  label = "meter"
}) {
  return (
    <meter
      aria-label={label}
      value={value}
      min={min}
      max={max}
      low={low}
      high={high}
    />
  );
}

What you did:

Tried to fetch by (implicit) meter role

What happened:

Failed to get element

Reproduction:

https://codesandbox.io/s/react-testing-library-getbyrole-meter-forked-ziqc09

Problem description:

Should be able to fetch a meter element by implicit role

Suggested solution:

@MatanBobi
Copy link
Member

Hi @idanen!
Thanks for opening this one :)
Looking at the spec, meter doesn't have an implicit role:
image
https://www.w3.org/TR/html-aria/

Where did you see that it does? Remember that aria-query follows the spec as is and browsers might not.

@idanen
Copy link
Collaborator Author

idanen commented Sep 20, 2022

Oh.. Actually I followed Chrome's behavior in its accessibility tab, which shows a role of meter on <meter /> elements.
So I guess this can be closed then?

@MatanBobi
Copy link
Member

Yeah, sorry about that :)

@MatanBobi MatanBobi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2022
@Blacktiger
Copy link

Blacktiger commented Nov 7, 2023

Maybe we should re-open this issue? Looks like the spec now specifies that meter is an implicit role.

Screenshot from docs showing the implicit meter role

https://www.w3.org/TR/html-aria/
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meter

Copy link

github-actions bot commented Nov 7, 2023

Uh oh! @Blacktiger, the image you shared is missing helpful alt text. Check #1171 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

@MatanBobi MatanBobi reopened this Nov 8, 2023
@MatanBobi
Copy link
Member

MatanBobi commented Nov 8, 2023

Thanks @Blacktiger!
I've tested this in our alpha version of @testing-library/dom and it works. We're testing it in multiple places to check for regressions so it's not yet released. If you want, you can install it manually also and see if that works for you.

@Blacktiger
Copy link

For now we just used a data-testid, but I'll definitely want to get our version upgraded when you guys do the final release. We really like how testing-library works and have been very happy with it, so thanks for all the work you guys have done on it.

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

3 participants