summaryrefslogtreecommitdiff
path: root/test/parallel/test-url-format-invalid-input.js
blob: 0f800496307921e2263b9d0336f4ba0a07117f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
require('../common');
const assert = require('assert');
const url = require('url');

const throwsObjsAndReportTypes = new Map([
  [undefined, 'undefined'],
  [null, 'null'],
  [true, 'boolean'],
  [false, 'boolean'],
  [0, 'number'],
  [function() {}, 'function'],
  [Symbol('foo'), 'symbol']
]);

for (const [obj, type] of throwsObjsAndReportTypes) {
  const error = new RegExp(
    `^TypeError: Parameter "urlObj" must be an object, not ${type}$`);
  assert.throws(function() { url.format(obj); }, error);
}
assert.strictEqual(url.format(''), '');
assert.strictEqual(url.format({}), '');