Nock is not working when I am using proxy
See original GitHub issueHello,
Nock seems unable to intercept the requests when I have declared environment variables HTTP_PROXY
and HTTPS_PROXY
. Could you please check on this?
Proxies are mandatory in my scenario, so I cant get rid of them.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
NodeJS - Nock doesn't intercept request made using the ` ...
In my tests, i'm trying to intercept HTTP request made by the request/request . But it doesn't work. When I use http.request() nock...
Read more >nock-proxy
Start using nock-proxy in your project by running `npm i nock-proxy`. There are no other projects in the npm registry using nock-proxy.
Read more >How to use the nock.restore function in nock
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >nock
This means that you can intercept 2 or more calls to the same URL and return different things on each of them. It...
Read more >Network Requests
You don't have to do any work on the server. Your application will have no idea its requests are being stubbed, so there...
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
Why didn’t I think of this earlier?! It works flawlessly now!
To everyone who are checking this issue, what I did to make it work is by writing these at the beginning of my code:
By doing so, nock will capture accordingly without being messed up by mocks.
Hmm, if I’m understanding correctly, it sounds like the requests are honoring the proxy, so they’re being made to the proxy host. To intercept those, you need to set mock requests for the proxied request on the proxy host.
Alternatively you could unset the proxy env vars when you’re running tests and leave your mocks on the real hosts.