-
-
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.
It now restricts to the valid values, and correctly defaults to "submit". We also add tests for the previous commit, about clicking a button triggering a submit, which only pass after this fix to the type property.
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
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,62 @@ | ||
"use strict"; | ||
const jsdom = require("../.."); | ||
|
||
exports["a button's type should be submit by default"] = function (t) { | ||
const doc = jsdom.jsdom(); | ||
const button = doc.createElement("button"); | ||
|
||
t.equal(button.type, "submit"); | ||
t.done(); | ||
}; | ||
|
||
exports["a button's type should stay within the range of valid values"] = function (t) { | ||
const doc = jsdom.jsdom(); | ||
const button = doc.createElement("button"); | ||
|
||
for (const type of ["reset", "button", "menu", "submit"]) { | ||
button.type = type; | ||
t.equal(button.type, type); | ||
|
||
button.type = type.toUpperCase(); | ||
t.equal(button.type, type); | ||
} | ||
|
||
button.type = "reset"; | ||
button.type = "asdfgdsafd"; | ||
t.equal(button.type, "submit"); | ||
|
||
button.type = "reset"; | ||
button.type = ""; | ||
t.equal(button.type, "submit"); | ||
|
||
t.done(); | ||
}; | ||
|
||
exports["clicking a button with .click() should trigger a submit"] = function (t) { | ||
const doc = jsdom.jsdom(); | ||
const form = doc.createElement("form"); | ||
const button = doc.createElement("button"); | ||
|
||
form.appendChild(button); | ||
form.addEventListener("submit", function (ev) { | ||
t.equal(ev.target, form); | ||
t.done(); | ||
}); | ||
|
||
button.click(); | ||
}; | ||
|
||
exports["clicking a button by dispatching an event should trigger a submit"] = function (t) { | ||
const doc = jsdom.jsdom(); | ||
const form = doc.createElement("form"); | ||
const button = doc.createElement("button"); | ||
|
||
form.appendChild(button); | ||
form.addEventListener("submit", function (ev) { | ||
t.equal(ev.target, form); | ||
t.done(); | ||
}); | ||
|
||
const e = new doc.defaultView.MouseEvent("click"); | ||
button.dispatchEvent(e); | ||
}; |
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