summaryrefslogtreecommitdiff
path: root/test/parallel/test-whatwg-url-custom-searchparams-stringifier.js
blob: e46865e8b014eb0cf3d8e02faafb8c3475ef80f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';

// Tests below are not from WPT.

require('../common');
const assert = require('assert');

{
  const params = new URLSearchParams();
  assert.throws(() => {
    params.toString.call(undefined);
  }, {
    code: 'ERR_INVALID_THIS',
    name: 'TypeError',
    message: 'Value of "this" must be of type URLSearchParams'
  });
}

// The URLSearchParams stringifier mutates the base URL using
// different percent-encoding rules than the URL itself.
{
  const myUrl = new URL('https://example.org?foo=~bar');
  assert.strictEqual(myUrl.search, '?foo=~bar');
  myUrl.searchParams.sort();
  assert.strictEqual(myUrl.search, '?foo=%7Ebar');
}