node/test/parallel/test-regress-GH-5727.js
Mithun Sasidharan eae0c05697
test: replace assert.throws w/ common.expectsError
PR-URL: https://github.com/nodejs/node/pull/17498
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
2017-12-08 16:02:07 -05:00

39 lines
958 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const invalidPort = -1 >>> 0;
net.Server().listen(0, function() {
const address = this.address();
const key = `${address.family.slice(-1)}:${address.address}:0`;
assert.strictEqual(this._connectionKey, key);
this.close();
});
// The first argument is a configuration object
common.expectsError(() => {
net.Server().listen({ port: invalidPort }, common.mustNotCall());
}, {
code: 'ERR_SOCKET_BAD_PORT',
type: RangeError
});
// The first argument is the port, no IP given.
common.expectsError(() => {
net.Server().listen(invalidPort, common.mustNotCall());
}, {
code: 'ERR_SOCKET_BAD_PORT',
type: RangeError
});
// The first argument is the port, the second an IP.
common.expectsError(() => {
net.Server().listen(invalidPort, '0.0.0.0', common.mustNotCall());
}, {
code: 'ERR_SOCKET_BAD_PORT',
type: RangeError
});