Skip to content

Commit

Permalink
test: fix dgram test
Browse files Browse the repository at this point in the history
- Fixed the dgram expected error message.
- Removed invalid addresses in the `dgram`'s
`Socket.prototype.send()` tests.
- Lowered the amount of expected anonymous function calls.
- Added a few missing invalid address test cases and made the valid
address test cases non-blocking.
- Added missing falsy values for the invalid address test check list.

test: remove invalid addresses

Removed invalid addresses in the `dgram`'s `Socket.prototype.send()`
tests.

test: lower expected function calls

Lowered the amount of expected anonymous function calls.

test: add missing and non-blocking cases

Added a few missing invalid address test cases
and made the valid address test cases
non-blocking.

test: omit invalid test case

Omitted the invalid anonymous function test case as the `address` parameter can also be a function.

test: add missing falsy values

Added missing falsy values for the invalid address test check list.
  • Loading branch information
VoltrexKeyva committed Jul 31, 2021
1 parent 0e2a475 commit 833caa4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/parallel/test-dgram-send-address-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@ const dgram = require('dgram');

const buf = Buffer.from('test');

const defaultCases = ['', null, undefined];

const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
}, 6);
}, defaultCases.length + 1);

const client = dgram.createSocket('udp4').bind(0, () => {
const port = client.address().port;

// Check valid addresses
[false, '', null, 0, undefined].forEach((address) => {
defaultCases.forEach((address) => {
client.send(buf, port, address, onMessage);
});

// Valid address: not provided
client.send(buf, port, onMessage);

// Check invalid addresses
[[], 1, true].forEach((invalidInput) => {
[
[],
0,
1,
true,
false,
0n,
1n,
{},
Symbol(),
].forEach((invalidInput) => {
const expectedError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "address" argument must be of type string or falsy.' +
message: 'The "address" argument must be of type string.' +
`${common.invalidArgTypeHelper(invalidInput)}`
};
assert.throws(() => client.send(buf, port, invalidInput), expectedError);
Expand Down

0 comments on commit 833caa4

Please sign in to comment.