summaryrefslogtreecommitdiff
path: root/test/parallel/test-dgram-sendto.js
diff options
context:
space:
mode:
authorMichael Dawson <mdawson@devrus.com>2017-05-09 14:18:35 -0400
committerMichael Dawson <michael_dawson@ca.ibm.com>2017-05-24 10:16:46 -0400
commite912c67d24ba42eeb47431a2b163f7f8a8532c78 (patch)
tree2fe7a1c11368a5f794599ac428560ac6de276bbe /test/parallel/test-dgram-sendto.js
parent1aad4ba2841120d04661681cd7a60b7124912d42 (diff)
downloadandroid-node-v8-e912c67d24ba42eeb47431a2b163f7f8a8532c78.tar.gz
android-node-v8-e912c67d24ba42eeb47431a2b163f7f8a8532c78.tar.bz2
android-node-v8-e912c67d24ba42eeb47431a2b163f7f8a8532c78.zip
dgram: convert to using internal/errors
Covert lib/dgram.js over to using lib/internal/errors.js for generating Errors. See [using-internal-errors.md](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md) for more details. I have not addressed the cases that use errnoException() and exceptionWithHostPort() helper methods as changing these would require fixing the tests across all of the different files that use them. In addition, these helpers already add a `code` to the Error and we'll have to discuss how that interacts with the `code` used by lib/internal/errors.js. I believe we should convert all users of errnoException and exceptionWithHostPort in a PR dedicated to that conversion. PR-URL: https://github.com/nodejs/node/pull/12926 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>
Diffstat (limited to 'test/parallel/test-dgram-sendto.js')
-rw-r--r--test/parallel/test-dgram-sendto.js38
1 files changed, 31 insertions, 7 deletions
diff --git a/test/parallel/test-dgram-sendto.js b/test/parallel/test-dgram-sendto.js
index 350f488f12..c922dc1039 100644
--- a/test/parallel/test-dgram-sendto.js
+++ b/test/parallel/test-dgram-sendto.js
@@ -1,24 +1,48 @@
'use strict';
-require('../common');
+const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
-const errorMessage =
- /^Error: Send takes "offset" and "length" as args 2 and 3$/;
+const errorMessageOffset =
+ /^The "offset" argument must be of type number$/;
assert.throws(() => {
socket.sendto();
-}, errorMessage);
+}, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: errorMessageOffset
+}));
assert.throws(() => {
socket.sendto('buffer', 1, 'offset', 'port', 'address', 'cb');
-}, errorMessage);
+}, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: /^The "length" argument must be of type number$/
+}));
assert.throws(() => {
socket.sendto('buffer', 'offset', 1, 'port', 'address', 'cb');
-}, errorMessage);
+}, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: errorMessageOffset
+}));
assert.throws(() => {
socket.sendto('buffer', 1, 1, 10, false, 'cb');
-}, /^Error: udp4 sockets must send to port, address$/);
+}, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: /^The "address" argument must be of type string$/
+}));
+
+assert.throws(() => {
+ socket.sendto('buffer', 1, 1, false, 'address', 'cb');
+}, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: /^The "port" argument must be of type number$/
+}));