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:
no console output since the event wasn't canceled
Actual:
"Event was canceled!" in console
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.
with basicHTML EventTarget.dispatchEvent does not return a boolean for cancelable events.
What I tried to do:
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 methodemit
. 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.