node/test/parallel/test-whatwg-url-custom-tostringtag.js
Joyee Cheung 6dd694c125
test: move custom WHATWG URL tests into separate files
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>
2018-08-25 08:57:23 +08:00

34 lines
1.0 KiB
JavaScript

'use strict';
// Tests below are not from WPT.
require('../common');
const assert = require('assert');
const URL = require('url').URL;
const toString = Object.prototype.toString;
const url = new URL('http://example.org');
const sp = url.searchParams;
const spIterator = sp.entries();
const test = [
[url, 'URL'],
[sp, 'URLSearchParams'],
[spIterator, 'URLSearchParams Iterator'],
// Web IDL spec says we have to return 'URLPrototype', but it is too
// expensive to implement; therefore, use Chrome's behavior for now, until
// spec is changed.
[Object.getPrototypeOf(url), 'URL'],
[Object.getPrototypeOf(sp), 'URLSearchParams'],
[Object.getPrototypeOf(spIterator), 'URLSearchParams Iterator'],
];
test.forEach(([obj, expected]) => {
assert.strictEqual(obj[Symbol.toStringTag], expected,
`${obj[Symbol.toStringTag]} !== ${expected}`);
const str = toString.call(obj);
assert.strictEqual(str, `[object ${expected}]`,
`${str} !== [object ${expected}]`);
});