Skip to content

Commit

Permalink
dispatchEvent now takes into account if an element has been disabled. F…
Browse files Browse the repository at this point in the history
…ixes jsdom#2665
  • Loading branch information
brendo committed Oct 9, 2019
1 parent e3744f5 commit 6922582
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/jsdom/living/nodes/HTMLElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class HTMLElementImpl extends ElementImpl {
}
}

dispatchEvent(eventImpl) {
if (isDisabled(this)) {
return;
}

return super.dispatchEvent(eventImpl);
}

click() {
// https://html.spec.whatwg.org/multipage/interaction.html#dom-click
// https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-mouse-event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@

}, "clicking a disabled button should not cause a click event");

async_test(t => {

const element = document.querySelector("#el1");
element.addEventListener("click", t.unreached_func("click event should never happen"));

element.dispatchEvent(new MouseEvent('click'));
t.step_timeout(() => t.done(), 500);

}, "dispatchEvent should not cause a click event");

async_test(t => {

const element = document.querySelector("#el2");
Expand Down

0 comments on commit 6922582

Please sign in to comment.