diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js index d064898aa9fd86..e00068cbde9097 100644 --- a/test/parallel/test-dgram-send-address-types.js +++ b/test/parallel/test-dgram-send-address-types.js @@ -3,49 +3,52 @@ const common = require('../common'); const assert = require('assert'); const dgram = require('dgram'); -const port = common.PORT; const buf = Buffer.from('test'); -const client = dgram.createSocket('udp4'); const onMessage = common.mustCall((err, bytes) => { assert.ifError(err); assert.strictEqual(bytes, buf.length); }, 6); -// valid address: false -client.send(buf, port, false, onMessage); +const expectedError = + /^TypeError: Invalid arguments: address must be a nonempty string or falsy$/; -// valid address: empty string -client.send(buf, port, '', onMessage); +const client = dgram.createSocket('udp4').bind(0, () => { -// valid address: null -client.send(buf, port, null, onMessage); + const port = client.address().port; -// valid address: 0 -client.send(buf, port, 0, onMessage); + // valid address: false + client.send(buf, port, false, onMessage); -// valid address: undefined -client.send(buf, port, undefined, onMessage); + // valid address: empty string + client.send(buf, port, '', onMessage); -// valid address: not provided -client.send(buf, port, onMessage); + // valid address: null + client.send(buf, port, null, onMessage); -const expectedError = - /^TypeError: Invalid arguments: address must be a nonempty string or falsy$/; + // valid address: 0 + client.send(buf, port, 0, onMessage); + + // valid address: undefined + client.send(buf, port, undefined, onMessage); + + // valid address: not provided + client.send(buf, port, onMessage); -// invalid address: object -assert.throws(() => { - client.send(buf, port, []); -}, expectedError); + // invalid address: object + assert.throws(() => { + client.send(buf, port, []); + }, expectedError); -// invalid address: nonzero number -assert.throws(() => { - client.send(buf, port, 1); -}, expectedError); + // invalid address: nonzero number + assert.throws(() => { + client.send(buf, port, 1); + }, expectedError); -// invalid address: true -assert.throws(() => { - client.send(buf, port, true); -}, expectedError); + // invalid address: true + assert.throws(() => { + client.send(buf, port, true); + }, expectedError); +}); client.unref();