mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 20:06:58 +00:00

To enable automatic update of WPT, move all our custom WHATWG URL tests that are not present in the upstream into files starting with `test-whatwg-url-custom-`, so it's easier to identify test cases that can be upstreamed and test cases that should be rolled into our repo (possibly with automation). PR-URL: https://github.com/nodejs/node/pull/22442 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const { URL, URLSearchParams } = require('url');
|
|
const { test, assert_array_equals, assert_unreached } =
|
|
require('../common/wpt');
|
|
|
|
/* The following tests are copied from WPT. Modifications to them should be
|
|
upstreamed first. Refs:
|
|
https://github.com/w3c/web-platform-tests/blob/a8b2b1e/url/urlsearchparams-foreach.html
|
|
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
|
|
*/
|
|
/* eslint-disable */
|
|
var i; // Strict mode fix for WPT.
|
|
test(function() {
|
|
var params = new URLSearchParams('a=1&b=2&c=3');
|
|
var keys = [];
|
|
var values = [];
|
|
params.forEach(function(value, key) {
|
|
keys.push(key);
|
|
values.push(value);
|
|
});
|
|
assert_array_equals(keys, ['a', 'b', 'c']);
|
|
assert_array_equals(values, ['1', '2', '3']);
|
|
}, "ForEach Check");
|
|
|
|
test(function() {
|
|
let a = new URL("http://a.b/c?a=1&b=2&c=3&d=4");
|
|
let b = a.searchParams;
|
|
var c = [];
|
|
for (i of b) {
|
|
a.search = "x=1&y=2&z=3";
|
|
c.push(i);
|
|
}
|
|
assert_array_equals(c[0], ["a","1"]);
|
|
assert_array_equals(c[1], ["y","2"]);
|
|
assert_array_equals(c[2], ["z","3"]);
|
|
}, "For-of Check");
|
|
|
|
test(function() {
|
|
let a = new URL("http://a.b/c");
|
|
let b = a.searchParams;
|
|
for (i of b) {
|
|
assert_unreached(i);
|
|
}
|
|
}, "empty");
|
|
/* eslint-enable */
|