mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
9d6af7d1fe
PR-URL: https://github.com/nodejs/node/pull/42650 Refs: https://coverage.nodejs.org/coverage-3c752648d4ef5510/lib/internal/url.js.html#L256 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// Tests below are not from WPT.
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const util = require('util');
|
|
|
|
const sp = new URLSearchParams('?a=a&b=b&b=c');
|
|
assert.strictEqual(util.inspect(sp),
|
|
"URLSearchParams { 'a' => 'a', 'b' => 'b', 'b' => 'c' }");
|
|
assert.strictEqual(util.inspect(sp, { depth: -1 }), '[Object]');
|
|
assert.strictEqual(
|
|
util.inspect(sp, { breakLength: 1 }),
|
|
"URLSearchParams {\n 'a' => 'a',\n 'b' => 'b',\n 'b' => 'c' }"
|
|
);
|
|
assert.strictEqual(util.inspect(sp.keys()),
|
|
"URLSearchParams Iterator { 'a', 'b', 'b' }");
|
|
assert.strictEqual(util.inspect(sp.values()),
|
|
"URLSearchParams Iterator { 'a', 'b', 'c' }");
|
|
assert.strictEqual(util.inspect(sp.keys(), { breakLength: 1 }),
|
|
"URLSearchParams Iterator {\n 'a',\n 'b',\n 'b' }");
|
|
assert.throws(() => sp[util.inspect.custom].call(), {
|
|
code: 'ERR_INVALID_THIS',
|
|
});
|
|
|
|
const iterator = sp.entries();
|
|
assert.strictEqual(util.inspect(iterator),
|
|
"URLSearchParams Iterator { [ 'a', 'a' ], [ 'b', 'b' ], " +
|
|
"[ 'b', 'c' ] }");
|
|
iterator.next();
|
|
assert.strictEqual(util.inspect(iterator),
|
|
"URLSearchParams Iterator { [ 'b', 'b' ], [ 'b', 'c' ] }");
|
|
iterator.next();
|
|
iterator.next();
|
|
assert.strictEqual(util.inspect(iterator),
|
|
'URLSearchParams Iterator { }');
|
|
const emptySp = new URLSearchParams();
|
|
assert.strictEqual(util.inspect(emptySp), 'URLSearchParams {}');
|