Skip to content

Commit

Permalink
Only log "not implemented" errors if form submission isn't canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
rolftimmermans authored and domenic committed Dec 18, 2016
1 parent 60555c0 commit 3c50533
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jsdom/living/nodes/HTMLFormElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HTMLFormElementImpl extends HTMLElementImpl {
_dispatchSubmitEvent() {
const ev = this._ownerDocument.createEvent("HTMLEvents");
ev.initEvent("submit", true, true);
if (!this.dispatchEvent(ev)) {
if (this.dispatchEvent(ev)) {
this.submit();
}
}
Expand Down
36 changes: 36 additions & 0 deletions test/jsdom/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,42 @@ describe("jsdom/miscellaneous", () => {
assert.equal(typeof elem.onsubmit, "function");
});

specify("form_onsubmit_not_implemented", () => {
const doc = jsdom.jsdom();

let error;
const vc = jsdom.getVirtualConsole(doc.defaultView);
vc.on("jsdomError", e => {
error = e;
});

const form = doc.createElement("form");
const bttn = doc.createElement("button");
form.appendChild(bttn);
bttn.click();

assert(error, "expected console to log not implemented error");
assert(error.message, "Not implemented: HTMLFormElement.prototype.submit");
});

specify("form_onsubmit_not_implemented_ignored_if_prevented", () => {
const doc = jsdom.jsdom();

let error;
const vc = jsdom.getVirtualConsole(doc.defaultView);
vc.on("jsdomError", e => {
error = e;
});

const form = doc.createElement("form");
form.addEventListener("submit", event => event.preventDefault());
const bttn = doc.createElement("button");
form.appendChild(bttn);
bttn.click();

assert(!error, "expected console to not log any error");
});

specify("get_element_by_id", () => {
const doc = jsdom.jsdom();
const el = doc.createElement("div");
Expand Down

0 comments on commit 3c50533

Please sign in to comment.