From 2a52a68a9680936044b3b7c6cc42a2f6be3c2b54 Mon Sep 17 00:00:00 2001 From: abouthiroppy Date: Thu, 19 Jan 2017 15:36:32 +0900 Subject: [PATCH] test: add dgram.Socket.prototype.bind's test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Colin Ihrig Reviewed-By: Claudio Rodriguez Reviewed-By: James M Snell Reviewed-By: Italo A. Casas Reviewed-By: Michaƫl Zasso --- test/parallel/test-dgram-bind.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-dgram-bind.js b/test/parallel/test-dgram-bind.js index 0bca97fb294f79..2d11fba6443ad8 100644 --- a/test/parallel/test-dgram-bind.js +++ b/test/parallel/test-dgram-bind.js @@ -1,13 +1,17 @@ 'use strict'; -require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); +const common = require('../common'); +const assert = require('assert'); +const dgram = require('dgram'); var socket = dgram.createSocket('udp4'); -socket.on('listening', function() { +socket.on('listening', common.mustCall(() => { + assert.throws(() => { + socket.bind(); + }, /^Error: Socket is already bound$/); + socket.close(); -}); +})); var result = socket.bind(); // should not throw