diff --git a/test/parallel/test-dns-lookupService.js b/test/parallel/test-dns-lookupService.js new file mode 100644 index 00000000000000..a935d18f2462df --- /dev/null +++ b/test/parallel/test-dns-lookupService.js @@ -0,0 +1,19 @@ +// Flags: --expose-internals +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cares = process.binding('cares_wrap'); +const { UV_ENOENT } = process.binding('uv'); +const dns = require('dns'); + +// Stub `getnameinfo` to *always* error. +cares.getnameinfo = () => UV_ENOENT; + +assert.throws( + () => dns.lookupService('127.0.0.1', 80, common.mustNotCall()), + { + code: 'ENOENT', + message: 'getnameinfo ENOENT 127.0.0.1', + syscall: 'getnameinfo' + } +);