nock: reqheaders ignored

Just hit my head against my monitor for a few minutes on this one… the documented way to match headers seems to have no effect. Whether my request has a header or not, it is matched by this:

nock('http://www.example.com', {
        reqheaders: {
          'authorization': 'Bearer TOKEN'
        }
      })
      .get('/users/52')
      .query(true)
      .reply(200);

But this (which I only found by digging into historical issues) works as I would expect, failing to match when the header is not provided

nock('http://www.example.com')
      .matchHeader('authorization', 'Bearer TOKEN')
      .get('/users/52')
      .query(true)
      .reply(200)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 22 (7 by maintainers)

Most upvoted comments

I’m not sure if it is due to SuperAgent, but that wouldn’t surprise me. Although the strange thing is that the headers are sent. Let me investigate a bit more tonight, I might be missing something.

I have exactly the same issue (reqheaders ignored but .matchHeader method works as expected). Using: Node: 8.6.0 Superagent: 3.7.0 Nock: 9.0.25

Tried with axios 0.17.0 and it worked perfectly fine (both reqheaders option and .matchHeader method matched requests correctly).

@csalvato I think that’s probably correct. Nock currently has a few issues with fetch (ex #409). I think we need to do an overhaul of nock soon to make fetch a first class citizen.