nodejs/test/parallel/test-http-hostname-typechecking.js
Rich Trott 5b1d12a092 test: restore no-op function in test
Remove common.mustCall() in test that might connect to a server already
running on the local host.

PR-URL: https://github.com/nodejs/node/pull/14065
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-07-04 06:54:21 -07:00

28 lines
927 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const http = require('http');
// All of these values should cause http.request() to throw synchronously
// when passed as the value of either options.hostname or options.host
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
const errHostname =
/^TypeError: "options\.hostname" must either be a string, undefined or null$/;
const errHost =
/^TypeError: "options\.host" must either be a string, undefined or null$/;
vals.forEach((v) => {
assert.throws(() => http.request({hostname: v}), errHostname);
assert.throws(() => http.request({host: v}), errHost);
});
// These values are OK and should not throw synchronously
['', undefined, null].forEach((v) => {
assert.doesNotThrow(() => {
http.request({hostname: v}).on('error', () => {}).end();
http.request({host: v}).on('error', () => {}).end();
});
});