test: add dgram.Socket.prototype.bind's test

Test that an error is thrown when bind() is called on an already bound
socket.

PR-URL: https://github.com/nodejs/node/pull/10894
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
abouthiroppy 2017-01-19 15:36:32 +09:00 committed by Michaël Zasso
parent 02ccffb081
commit ff75e21662

View File

@ -1,13 +1,17 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.on('listening', function() {
socket.on('listening', common.mustCall(() => {
assert.throws(() => {
socket.bind();
}, /^Error: Socket is already bound$/);
socket.close();
});
}));
const result = socket.bind(); // should not throw