-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't fire submit event from form.submit()
Fixes #3435.
- Loading branch information
Showing
3 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# jsdom-only tests | ||
|
||
This directory contains WPT-style tests that are jsdom-specific, and thus should not be run in browsers nor upstreamed (despite living under `to-upstream`). Since jsdom follows the platform wherever possible, these should be extremely rare. | ||
|
||
The intended use case is for verifying jsdom behavior that can't (or needn't) be tested in browsers (e.g. validating `HTMLFormElement.prototyope.submit()`'s behavior without actually navigating). If the test will also pass in browsers, then it should be in a different directory. |
28 changes: 28 additions & 0 deletions
28
test/web-platform-tests/to-upstream/jsdom-only/form-submit.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Form submit event</title> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<form><button></button></form> | ||
|
||
<body> | ||
<script> | ||
"use strict"; | ||
|
||
// There's no reliable way to prevent browser navigation on form.submit(), and all browsers get this right, so this | ||
// is a jsdom-only test | ||
test(() => { | ||
let submitEvent; | ||
const form = document.querySelector("form"); | ||
form.addEventListener("submit", event => { | ||
event.preventDefault(); | ||
submitEvent = event; | ||
}); | ||
|
||
form.submit(); | ||
|
||
assert_equals(submitEvent, undefined, "SubmitEvent does not fire"); | ||
}, "HTMLFormElement's submit() does not fire a SubmitEvent"); | ||
</script> |