mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 12:03:30 +00:00

There is actually no reason to use `assert.doesNotThrow()` in the tests. If a test throws, just let the error bubble up right away instead of first catching it and then rethrowing it. PR-URL: https://github.com/nodejs/node/pull/18669 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
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()];
|
|
|
|
vals.forEach((v) => {
|
|
common.expectsError(
|
|
() => http.request({ hostname: v }),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "options.hostname" property must be one of ' +
|
|
'type string, undefined, or null. ' +
|
|
`Received type ${typeof v}`
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => http.request({ host: v }),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "options.host" property must be one of ' +
|
|
'type string, undefined, or null. ' +
|
|
`Received type ${typeof v}`
|
|
}
|
|
);
|
|
});
|
|
|
|
// These values are OK and should not throw synchronously.
|
|
// Only testing for 'hostname' validation so ignore connection errors.
|
|
const dontCare = () => {};
|
|
['', undefined, null].forEach((v) => {
|
|
http.request({ hostname: v }).on('error', dontCare).end();
|
|
http.request({ host: v }).on('error', dontCare).end();
|
|
});
|