0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/internet/test-dns-promises-resolve.js
Ruben Bridgewater ac2fc0dd5f
errors: improve ERR_INVALID_ARG_TYPE
ERR_INVALID_ARG_TYPE is the most common error used throughout the
code base. This improves the error message by providing more details
to the user and by indicating more precisely which values are allowed
ones and which ones are not.

It adds the actual input to the error message in case it's a primitive.
If it's a class instance, it'll print the class name instead of
"object" and "falsy" or similar entries are not named "type" anymore.

PR-URL: https://github.com/nodejs/node/pull/29675
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-12-20 03:10:13 +01:00

43 lines
1020 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dnsPromises = require('dns').promises;
// Error when rrtype is invalid.
{
const rrtype = 'DUMMY';
common.expectsError(
() => dnsPromises.resolve('example.org', rrtype),
{
code: 'ERR_INVALID_OPT_VALUE',
type: TypeError,
message: `The value "${rrtype}" is invalid for option "rrtype"`
}
);
}
// Error when rrtype is a number.
{
const rrtype = 0;
common.expectsError(
() => dnsPromises.resolve('example.org', rrtype),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "rrtype" argument must be of type string. ' +
`Received type ${typeof rrtype} (${rrtype})`
}
);
}
// Setting rrtype to undefined should work like resolve4.
{
(async function() {
const rrtype = undefined;
const result = await dnsPromises.resolve('example.org', rrtype);
assert.ok(result !== undefined);
assert.ok(result.length > 0);
})();
}