@@ -4,12 +4,14 @@ const common = require('../common');
44const assert = require ( 'assert' ) ;
55const { internalBinding } = require ( 'internal/test/binding' ) ;
66const cares = internalBinding ( 'cares_wrap' ) ;
7+
8+ // Stub `getaddrinfo` to *always* error. This has to be done before we load the
9+ // `dns` module to guarantee that the `dns` module uses the stub.
10+ cares . getaddrinfo = ( ) => internalBinding ( 'uv' ) . UV_ENOMEM ;
11+
712const dns = require ( 'dns' ) ;
813const dnsPromises = dns . promises ;
914
10- // Stub `getaddrinfo` to *always* error.
11- cares . getaddrinfo = ( ) => internalBinding ( 'uv' ) . UV_ENOENT ;
12-
1315{
1416 const err = {
1517 code : 'ERR_INVALID_ARG_TYPE' ,
@@ -144,15 +146,19 @@ dns.lookup('127.0.0.1', {
144146
145147let tickValue = 0 ;
146148
149+ // Should fail due to stub.
147150dns . lookup ( 'example.com' , common . mustCall ( ( error , result , addressType ) => {
148151 assert ( error ) ;
149152 assert . strictEqual ( tickValue , 1 ) ;
150- assert . strictEqual ( error . code , 'ENOENT ' ) ;
153+ assert . strictEqual ( error . code , 'ENOMEM ' ) ;
151154 const descriptor = Object . getOwnPropertyDescriptor ( error , 'message' ) ;
152155 // The error message should be non-enumerable.
153156 assert . strictEqual ( descriptor . enumerable , false ) ;
154157} ) ) ;
155158
156- // Make sure that the error callback is called
157- // on next tick.
159+ // Make sure that the error callback is called on next tick.
158160tickValue = 1 ;
161+
162+ // Should fail due to stub.
163+ assert . rejects ( dnsPromises . lookup ( 'example.com' ) ,
164+ { code : 'ENOMEM' , hostname : 'example.com' } ) ;
0 commit comments