1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const dgram = require('dgram'); 5 6const buf = Buffer.from('test'); 7 8const onMessage = common.mustSucceed((bytes) => { 9 assert.strictEqual(bytes, buf.length); 10}, 6); 11 12const client = dgram.createSocket('udp4').bind(0, () => { 13 const port = client.address().port; 14 15 // Check valid addresses 16 [false, '', null, 0, undefined].forEach((address) => { 17 client.send(buf, port, address, onMessage); 18 }); 19 20 // Valid address: not provided 21 client.send(buf, port, onMessage); 22 23 // Check invalid addresses 24 [[], 1, true].forEach((invalidInput) => { 25 const expectedError = { 26 code: 'ERR_INVALID_ARG_TYPE', 27 name: 'TypeError', 28 message: 'The "address" argument must be of type string or falsy.' + 29 `${common.invalidArgTypeHelper(invalidInput)}` 30 }; 31 assert.throws(() => client.send(buf, port, invalidInput), expectedError); 32 }); 33}); 34 35client.unref(); 36