`nock` does not support the new Node.js 10.9 signature `http.request(url[, options][, callback])`
See original GitHub issueWhat is the expected behavior?
Using the new signature for http.request(url, options[, callback])
/http.get(url, options[, callback])
(introduced in Node.js v10.9, should work with nock
.
What is the actual behavior?
With nock
(by merely require
ing nock
), it throws:
events.js:288
throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
at ClientRequest.once (events.js:288:11)
at new ClientRequest (_http_client.js:150:10)
at Object.request (http.js:41:10)
at ...\node_modules\nock\lib\intercept.js:405:16
at Object.module.request (...\node_modules\nock\lib\common.js:140:14)
at requestWithUrlAndOptions (...\script.js:27:5)
at Object.<anonymous> (...\script.js:42:1)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
Possible solution
I haven’t looked at the code, but I suspect nock
assumes the second argument is always the callback and uses it as such, whereas in Node.js 10.9+, the second argument can be an object (with the third being the callback). It should be trivial to detect that situation and pass the correct arguments to http.request()
(or something like that 😁).
How to reproduce the issue
Runkit: Example link
Does the bug have a test case? (Not sure wht this means.)
Versions
Software | Version(s) |
---|---|
Nock | All (at least up to 10.0.0) |
Node | 10.9+ |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
HTTP | Node.js v19.3.0 Documentation
maxHeaderSize; http.request(options[, callback]); http.request(url[, ... It parses a message into headers and body but it does not parse the actual headers ...
Read more >How is an HTTP POST request made in node.js?
My program doesn't actually send the http request post when I keep the function handling errors. Once I deleted it, it worked. Your...
Read more >nock: Versions - Openbase
(Added in v11.3); Add support for the http.request signatures added in Node 10.9; Scopes can be filtered using the system environment or any...
Read more >nock - Devpost
Nock is an HTTP mocking and expectations library for Node.js ... or if host is not part of it, Nock will automatically add...
Read more >Embed a CLA Signing Page Using NodeJS with the HelloSign ...
Get your CLAs signed easier using the Dropbox Sign API and GitHub API. ... is not the case, go to Nodejs.org and get...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gr2m I’ll join in on the fun 😃, just submitted a PR (https://github.com/nock/nock/pull/1428) that fixes this bug. Would be cool if someone could review it.
🎉 This issue has been resolved in version 11.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀