Skip to content

Commit e46b8ed

Browse files
MarkArranzBridgeAR
authored andcommitted
test: add error code tests in dgram test
Improve error validation in test-dgram-send-bad-arguments. PR-URL: #24215 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 6076ccf commit e46b8ed

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

test/parallel/test-dgram-send-bad-arguments.js

+29-6
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,48 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const dgram = require('dgram');
2626

2727
const buf = Buffer.from('test');
2828
const host = '127.0.0.1';
2929
const sock = dgram.createSocket('udp4');
3030

31-
assert.throws(() => {
32-
sock.send();
33-
}, TypeError); // First argument should be a buffer.
31+
// First argument should be a buffer.
32+
common.expectsError(
33+
() => { sock.send(); },
34+
{
35+
code: 'ERR_INVALID_ARG_TYPE',
36+
type: TypeError,
37+
message: 'The "buffer" argument must be one of type ' +
38+
'Buffer, Uint8Array, or string. Received type undefined'
39+
}
40+
);
3441

3542
// send(buf, offset, length, port, host)
3643
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
3744
assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);
3845
assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError);
3946

4047
// send(buf, port, host)
41-
assert.throws(() => { sock.send(23, 12345, host); }, TypeError);
48+
common.expectsError(
49+
() => { sock.send(23, 12345, host); },
50+
{
51+
code: 'ERR_INVALID_ARG_TYPE',
52+
type: TypeError,
53+
message: 'The "buffer" argument must be one of type ' +
54+
'Buffer, Uint8Array, or string. Received type number'
55+
}
56+
);
4257

4358
// send([buf1, ..], port, host)
44-
assert.throws(() => { sock.send([buf, 23], 12345, host); }, TypeError);
59+
common.expectsError(
60+
() => { sock.send([buf, 23], 12345, host); },
61+
{
62+
code: 'ERR_INVALID_ARG_TYPE',
63+
type: TypeError,
64+
message: 'The "buffer list arguments" argument must be one of type ' +
65+
'Buffer or string. Received type object'
66+
}
67+
);

0 commit comments

Comments
 (0)