2017-01-28 10:23:47 +01:00
|
|
|
'use strict';
|
2017-06-28 18:12:12 +02:00
|
|
|
const common = require('../common');
|
2017-01-28 10:23:47 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const url = require('url');
|
|
|
|
|
2017-02-04 14:39:20 +01:00
|
|
|
const throwsObjsAndReportTypes = new Map([
|
|
|
|
[undefined, 'undefined'],
|
|
|
|
[null, 'null'],
|
|
|
|
[true, 'boolean'],
|
|
|
|
[false, 'boolean'],
|
|
|
|
[0, 'number'],
|
|
|
|
[function() {}, 'function'],
|
|
|
|
[Symbol('foo'), 'symbol']
|
|
|
|
]);
|
|
|
|
|
2017-07-03 09:09:11 +02:00
|
|
|
for (const [urlObject, type] of throwsObjsAndReportTypes) {
|
2017-06-28 18:12:12 +02:00
|
|
|
const error = common.expectsError({
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
2017-07-03 09:09:11 +02:00
|
|
|
message: 'The "urlObject" argument must be one of type object or string. ' +
|
2017-06-28 18:12:12 +02:00
|
|
|
`Received type ${type}`
|
|
|
|
});
|
2017-07-03 09:09:11 +02:00
|
|
|
assert.throws(function() { url.format(urlObject); }, error);
|
2017-01-28 10:23:47 +01:00
|
|
|
}
|
|
|
|
assert.strictEqual(url.format(''), '');
|
|
|
|
assert.strictEqual(url.format({}), '');
|