mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 18:44:40 +00:00

Added comments to whatwg-url tests that they should not be changed until modifications are merged upstream as per "Web Platform Tests" guidelines PR-URL: https://github.com/nodejs/node/pull/14355 Fixes: https://github.com/nodejs/node/issues/12793 Refs: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com>
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
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 */
|
|
|
|
// Tests below are not from WPT.
|
|
{
|
|
const params = new URLSearchParams();
|
|
assert.throws(() => {
|
|
params.forEach.call(undefined);
|
|
}, common.expectsError({
|
|
code: 'ERR_INVALID_THIS',
|
|
type: TypeError,
|
|
message: 'Value of "this" must be of type URLSearchParams'
|
|
}));
|
|
}
|