question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nock.log is silent when headers don't match

See original GitHub issue

What is the expected behavior? If I use

nock('https://example.com/my_url', { reqheader }).log(console.log);

I would expect that a request to https://example.com would be checked against that route and that the logging would show that.

What is the actual behavior?

Nothing is logged to the console if the headers do not match the specified reqheader This is confusing behaviour and makes people thinks that the nock setups are not being called

Possible solution

Output the attempted match to the console

How to reproduce the issue

Here’s an example, commenting out the reqheader results in the attempted match being logged

Runkit: Example link

Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.

Does the bug have a test case?

Versions

Software Version(s)
Nock 12.0.3
Node v10.17.0
TypeScript

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
mastermattcommented, Mar 30, 2020

Nock does not actually intercept a request unless reply() is called after creating an Interceptor with a verb method. Also the correct option name is reqheaders (plural).

nock('https://example.com', { reqheaders })
  .log(console.log)
  .get('/my_url')
  .reply();

This type of question/issue comes up a lot on Github and Stackoverflow. It’s pretty obvious the Readme isn’t sufficient and needs to be updated to cover this nuance. Maybe a second paragraph to READ THIS! - About interceptors

1reaction
mastermattcommented, Apr 2, 2020

What do we think about this https://github.com/nock/nock/pull/1966 ?

@chrisjensen there can’t be a bug with .log() if there is no .log(). 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to see if nock is matching the request or not?
It is very simple. Just add .log(console.log) to your nock object!
Read more >
Nock: HTTP Mocking and Expectations - Morioh
If no request headers are specified for mocking then Nock will automatically skip matching of request headers. Since the host header is a...
Read more >
Logging & Debugging - MockServer
The simplest way to debug MockServer is to use the UI to view logs, requests and ... both proxied requests and requests that...
Read more >
nock - npm
If no request headers are specified for mocking then Nock will automatically skip matching of request headers.
Read more >
Nocks: So Small, Yet So Critical to Accuracy! - Nock On Archery
The first is how your nock fits onto your bow string. Proper “nock fit” is critical. If the string is too tight on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found