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

Active element does not target the same in test as in browser #434

Closed
daBack opened this issue Mar 30, 2022 · 3 comments · Fixed by #436
Closed

Active element does not target the same in test as in browser #434

daBack opened this issue Mar 30, 2022 · 3 comments · Fixed by #436
Assignees
Labels
bug Something isn't working high priority

Comments

@daBack
Copy link

daBack commented Mar 30, 2022

Heyoh! :)

Issue:
When testing focus, we are dispatching keydown events, which triggers a focus change. This works all fine and dandy in the code and in our project. In the test however, the activeElement is not behaving as in the browser.

Example:

<AWebComponent>
  /* in aWebComponents shadowRoot below */
  <button></button>
</AWebComponent>

Expected behaviour:
The activeElement is in the code and the browser AWebComponent.

Actual behaviour:
In our tests, activeElement is button.

This makes it difficult to test the focus, since the logic in the component doesn't work for the test and it targets the wrong elements.
We believe that the activeElement in happy dom is always returning the lowest element in the hierarchy, in this case button, but the browser returns AWebComponent.

It would be awesome if the tests would return the same activeElement object. Is this something that's doable, or something that we have missed?

Regards,
Bäck

@capricorn86
Copy link
Owner

Thank you for reporting @daBack! 🙂

I will look into fixing this as soon as possible.

@capricorn86 capricorn86 added bug Something isn't working high priority labels Mar 30, 2022
@capricorn86 capricorn86 self-assigned this Mar 30, 2022
capricorn86 pushed a commit that referenced this issue Mar 30, 2022
…st custom element that has document as root node when the focused element is nestled in shadow roots.
capricorn86 added a commit that referenced this issue Mar 30, 2022
…-not-target-the-same-in-test-as-in-browser

#434@patch: Fixes issue with Document.activeElement not being the fir…
@capricorn86
Copy link
Owner

I have now fixed the issue 🙂

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v2.51.1

@capricorn86
Copy link
Owner

@daBack ☝️

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

Successfully merging a pull request may close this issue.

2 participants