WebReflection / basicHTML

A NodeJS based, standard oriented, HTML implementation.
ISC License
126 stars 10 forks source link

dispatchEvent does not return a boolean for cancelable events #37

Closed noramass closed 5 years ago

noramass commented 5 years ago

with basicHTML EventTarget.dispatchEvent does not return a boolean for cancelable events.

What I tried to do:

const div = document.createElement("div");
if( !div.dispatchEvent(new CustomEvent("some-event", {cancelable: true})) )
  console.log("Event was canceled!");

Expected Behavior:

Actual:

Use Case: I am unit testing a webcomponent library with multiple decorators, one of them being the property decorator @Event. This decorator populates the property on first access with a bound event emitter. This emitter provides a method emit. This method takes a detail object as an argument and returns the result of dispatchEvent. To properly unit test this functionality, dispatchEvent has to return a boolean if a cancelable event has been canceled.

Workaround: My current workaround is to create the event, emit it and check if it returned a boolean, if it did not, it will check the defaultPrevented property afterwards.