@@ -249,12 +249,16 @@ function overrideClientRequest() {
249249 // Define the overriding client request that nock uses internally.
250250 function OverriddenClientRequest ( options , cb ) {
251251 if ( ! options ) {
252- // In principle, there is no reason we couldn't support this. However it
253- // doesn't work, and fixing it seems low priority. Giving an explicit
254- // error seems nicer than crashing with a weird stack trace.
252+ // As weird as it is, it's possible to call `http.request` without
253+ // options, and it makes a request to localhost or somesuch. We should
254+ // support it too, for parity. However it doesn't work today, and fixing
255+ // it seems low priority. Giving an explicit error is nicer than
256+ // crashing with a weird stack trace. `http[s].request()`, nock's other
257+ // client-facing entry point, makes a similar check.
255258 // https://github.com/nock/nock/pull/1386
259+ // https://github.com/nock/nock/pull/1440
256260 throw Error (
257- 'Creating a client request with empty `options` is not supported in Nock'
261+ 'Creating a ClientRequest with empty `options` is not supported in Nock'
258262 )
259263 }
260264
@@ -386,6 +390,18 @@ function activate() {
386390 options = urlParse ( options )
387391 } else if ( options instanceof URL ) {
388392 options = urlParse ( options . toString ( ) )
393+ } else if ( ! options ) {
394+ // As weird as it is, it's possible to call `http.request` without
395+ // options, and it makes a request to localhost or somesuch. We should
396+ // support it too, for parity. However it doesn't work today, and fixing
397+ // it seems low priority. Giving an explicit error is nicer than
398+ // crashing with a weird stack trace. `new ClientRequest()`, nock's
399+ // other client-facing entry point, makes a similar check.
400+ // https://github.com/nock/nock/pull/1386
401+ // https://github.com/nock/nock/pull/1440
402+ throw Error (
403+ 'Making a request with empty `options` is not supported in Nock'
404+ )
389405 }
390406 options . proto = proto
391407
0 commit comments