mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
Fix URLSearchParams set() and constructor() (#1368)
This commit is contained in:
parent
528eb2adb3
commit
3dbd18af09
2 changed files with 57 additions and 4 deletions
|
@ -59,11 +59,18 @@ test(function urlSearchParamsHasSuccess() {
|
|||
assert(!searchParams.has("c"));
|
||||
});
|
||||
|
||||
test(function urlSearchParamsSetSuccess() {
|
||||
test(function urlSearchParamsSetReplaceFirstAndRemoveOthers() {
|
||||
const init = "a=54&b=true&a=true";
|
||||
const searchParams = new URLSearchParams(init);
|
||||
searchParams.set("a", "false");
|
||||
assertEqual(searchParams.toString(), "b=true&a=false");
|
||||
assertEqual(searchParams.toString(), "a=false&b=true");
|
||||
});
|
||||
|
||||
test(function urlSearchParamsSetAppendNew() {
|
||||
const init = "a=54&b=true&a=true";
|
||||
const searchParams = new URLSearchParams(init);
|
||||
searchParams.set("c", "foo");
|
||||
assertEqual(searchParams.toString(), "a=54&b=true&a=true&c=foo");
|
||||
});
|
||||
|
||||
test(function urlSearchParamsSortSuccess() {
|
||||
|
@ -112,3 +119,22 @@ test(function urlSearchParamsMissingPair() {
|
|||
const searchParams = new URLSearchParams(init);
|
||||
assertEqual(searchParams.toString(), "c=4&a=54");
|
||||
});
|
||||
|
||||
// If pair does not contain exactly two items, then throw a TypeError.
|
||||
// ref https://url.spec.whatwg.org/#interface-urlsearchparams
|
||||
test(function urlSearchParamsShouldThrowTypeError() {
|
||||
let hasThrown = 0;
|
||||
|
||||
try {
|
||||
new URLSearchParams([["1"]]);
|
||||
hasThrown = 1;
|
||||
} catch (err) {
|
||||
if (err instanceof TypeError) {
|
||||
hasThrown = 2;
|
||||
} else {
|
||||
hasThrown = 3;
|
||||
}
|
||||
}
|
||||
|
||||
assertEqual(hasThrown, 2);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue