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

"this" is undefined in event listeners #415

Closed
Bauke opened this issue Mar 16, 2022 · 1 comment · Fixed by #416
Closed

"this" is undefined in event listeners #415

Bauke opened this issue Mar 16, 2022 · 1 comment · Fixed by #416
Assignees
Labels
bug Something isn't working high priority

Comments

@Bauke
Copy link

Bauke commented Mar 16, 2022

Came across this issue while trying to get HTM + Preact working with Happy DOM:

import {GlobalRegistrator} from '@happy-dom/global-registrator';

GlobalRegistrator.register();

const button = document.createElement('button');
button.textContent = 'A Button';

button.addEventListener('click', function () {
  console.log(this === undefined, this.textContent);
  // Results in: TypeError: Cannot read properties of undefined (reading 'textContent')
});

button.click();
@capricorn86 capricorn86 self-assigned this Mar 16, 2022
@capricorn86 capricorn86 added bug Something isn't working high priority labels Mar 16, 2022
capricorn86 added a commit that referenced this issue Mar 16, 2022
…e of the EventTarget when calling EventTarget.dispatchEvent().
capricorn86 added a commit that referenced this issue Mar 16, 2022
…n-event-listeners

#415@patch: Fixes bug where event listeners wasn't called in the scop…
@capricorn86
Copy link
Owner

Thank you for reporting @Bauke! 🙂

I have fixed the bug.

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

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