summaryrefslogtreecommitdiff
path: root/test/parallel/test-url-format-invalid-input.js
blob: 1a0df32657ece89d92eaae922db02319ed1fcb49 (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
27
'use strict';
const common = require('../common');
const assert = require('assert');
const url = require('url');

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

for (const [urlObject, type] of throwsObjsAndReportTypes) {
  common.expectsError(function() {
    url.format(urlObject);
  }, {
    code: 'ERR_INVALID_ARG_TYPE',
    type: TypeError,
    message: 'The "urlObject" argument must be one of type Object or string. ' +
             `Received type ${type}`
  });
}
assert.strictEqual(url.format(''), '');
assert.strictEqual(url.format({}), '');