capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.39k stars 204 forks source link

Missing implementation in addEventListener #226

Closed dkocsis-emarsys closed 3 years ago

dkocsis-emarsys commented 3 years ago

Hi there!

First of all, this is an awesome library. I'm working with web-components so this is a great help for unit testing them!

However, I think I've found a bug where you can't pass an object as second parameter to the addEventListener function. It should call the object's handleEvent function with the event as a parameter.

const myObject = {
  handleEvent: console.log
};

const button = document.createElement('button');
button.addEventListener('click', myObject);
button.click();

Running this code from a browser console results a log, but doing the same in happy-dom's context will result an error: TypeError listener is not a function

Have a nice day! David

capricorn86 commented 3 years ago

Thanks for reporting @dkocsis-emarsys! :slightly_smiling_face:

I will fix it as soon as possible. Probably tomorrow.

capricorn86 commented 3 years ago

I have added a fix now :slightly_smiling_face:

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

You have a nice name by the way :slightly_smiling_face:

// David