0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-socket-address.js
Daniel Bevenius cf980b0311 net: check and throw on error for getsockname
This commit attempts fix a TODO in net.js:
TODO(bnoordhuis) Check err and throw?

PR-URL: https://github.com/nodejs/node/pull/12871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-05-09 12:36:51 +02:00

18 lines
481 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
// This tests checks that if server._handle.getsockname
// returns an error number, an error is thrown.
const server = net.createServer({});
server.listen(0, common.mustCall(function() {
server._handle.getsockname = function(out) {
return -1;
};
assert.throws(() => this.address(),
/^Error: address ([\w|\s-\d])+$/);
server.close();
}));