mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 20:06:58 +00:00

This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
37 lines
1014 B
JavaScript
37 lines
1014 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
|
|
const buf = Buffer.from('test');
|
|
|
|
const onMessage = common.mustCall((err, bytes) => {
|
|
assert.ifError(err);
|
|
assert.strictEqual(bytes, buf.length);
|
|
}, 6);
|
|
|
|
const client = dgram.createSocket('udp4').bind(0, () => {
|
|
const port = client.address().port;
|
|
|
|
// Check valid addresses
|
|
[false, '', null, 0, undefined].forEach((address) => {
|
|
client.send(buf, port, address, onMessage);
|
|
});
|
|
|
|
// Valid address: not provided
|
|
client.send(buf, port, onMessage);
|
|
|
|
// Check invalid addresses
|
|
[[], 1, true].forEach((invalidInput) => {
|
|
const expectedError = {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
|
|
message: 'The "address" argument must be one of type string or falsy. ' +
|
|
`Received type ${typeof invalidInput}`
|
|
};
|
|
assert.throws(() => client.send(buf, port, invalidInput), expectedError);
|
|
});
|
|
});
|
|
|
|
client.unref();
|