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 does not work in some cases #1122

Closed
roman-gula opened this issue Oct 6, 2023 · 2 comments · Fixed by #1310
Closed

getByRole does not work in some cases #1122

roman-gula opened this issue Oct 6, 2023 · 2 comments · Fixed by #1310
Assignees
Labels
bug Something isn't working

Comments

@roman-gula
Copy link

Describe the bug
Hi! I use Vite with MUI and noticed that with happy-dom my test fails. With jsdom it works.
I can't find what is the problem. Please see code below

To Reproduce

it('with Accordion', () => {
  render(
    <Accordion>
      <AccordionSummary>aaa</AccordionSummary>
    </Accordion>
  );

  expect(screen.getByRole('button')).toBeInTheDocument();
});

Example on Stackblitz

@roman-gula roman-gula added the bug Something isn't working label Oct 6, 2023
@DavidRNogueira
Copy link

I also have this issue when using different component libraries. The issue seems to be that HappyDOM may not be looking at the role attribute, but rather its only looking at the actual element type? The component library is also using a div with role="button" and HappyDOM does not pick it up properly.

@capricorn86 capricorn86 self-assigned this Mar 14, 2024
capricorn86 added a commit that referenced this issue Mar 14, 2024
…k-in-some-cases

fix: [#1122] Fixes problem related to invalid pseudo query selectors …
@capricorn86
Copy link
Owner

Thank you for reporting @roman-gula and @DavidRNogueira! 🙂

A fix has been released:
https://github.com/capricorn86/happy-dom/releases/tag/v13.8.5

The reason for why it failed to match the element is because Testing Library checks if the element is visible by using Window.getComputedStyle(), which returned display: none for the button element. The button element had display: none as a CSS rule with the pseudo selector ":before" matched the actual element (and not the pseudo element), but shouldn't have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants