|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21 | 21 |
|
22 | 22 | 'use strict';
|
23 |
| -require('../common'); |
| 23 | +const common = require('../common'); |
24 | 24 | const assert = require('assert');
|
25 | 25 | const dgram = require('dgram');
|
26 | 26 |
|
27 | 27 | const buf = Buffer.from('test');
|
28 | 28 | const host = '127.0.0.1';
|
29 | 29 | const sock = dgram.createSocket('udp4');
|
30 | 30 |
|
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 | +); |
34 | 41 |
|
35 | 42 | // send(buf, offset, length, port, host)
|
36 | 43 | assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
|
37 | 44 | assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);
|
38 | 45 | assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError);
|
39 | 46 |
|
40 | 47 | // 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 | +); |
42 | 57 |
|
43 | 58 | // 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