question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`*byRole("listbox")` does not properly query <select /> elements

See original GitHub issue
  • @testing-library/dom version: @testing-library/dom@8.11.0
  • Testing Framework and version: @testing-library/cypress@8.0.2
  • DOM Environment: Cypress/browser (though the issue is reproduced in the Codesandbox that follows via Jest/JSDom)

Relevant code or config:

<label for="my-select">My Select</label>

<select id="my-select"></select>
// Using `dom-testing-library` via `cypress-testing-library`
cy.findByRole("listbox", { name: "My Select" }); // Doesn't work, element not found
cy.findByRole("combobox", { name: "My Select" }); // Does work! But this isn't the right ARIA role

What you did:

What happened:

Reproduction:

Codesandbox reproduction

Problem description:

  • A <select /> should be query-able via *byRole("listbox")

Suggested solution:

Thanks for all of your great work on this library - it’s truly a game changer in the space 🎉

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nicklemmoncommented, Dec 23, 2021

@MatanBobi we sure can! Appreciate your help and your work on this library. Happy New Year to you as well.

1reaction
MatanBobicommented, Dec 23, 2021

@nicklemmon I looked into the spec a little more and found this:

image

Since this is the wanted behavior, can we close this one? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ByRole | Testing Library
An element with the heading role can be queried by any heading level getByRole('heading') or by a specific heading level using the level...
Read more >
byRole is not returning the DOM element - Stack Overflow
TestingLibraryElementError: Unable to find an accessible element with the role "listbox" There are no accessible roles.
Read more >
`selectOptions` doesn't work when 'listbox' lives outside of ...
It's because the current logic looks for options inside the given select element, and in the given scenario, it can't find any and...
Read more >
React Testing Library Confusion : r/reactjs - Reddit
Right now, I have just two tests: one checks for a non-multiple select that is not disabled. I find it with this: screen.queryByLabelText(" ......
Read more >
ARIA: listbox role - Accessibility - MDN Web Docs - Mozilla
The listbox role is used for lists from which a user may select one or ... This is a space-separated list of element...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found