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