Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock header doesn't work #765

Closed
ianaz opened this issue Nov 29, 2016 · 3 comments
Closed

Mock header doesn't work #765

ianaz opened this issue Nov 29, 2016 · 3 comments
Labels

Comments

@ianaz
Copy link

ianaz commented Nov 29, 2016

Using:
nock 9.0.2,
NodeJS v7.0.0
Windows 7

By using the following code:

nock('http://test.com').persist().get('/user/tokeninfo', {
    reqheaders: {
        authorization: 'Bearer VALID_JWT'
    }
}).reply(200);

and then making the call with

        return fetch('http://test.com/user/tokeninfo', {
            headers: {
                authorization: 'Bearer VALID_JWT'
            }
        })
            .then((res) => {
                return true;
            })
            .catch((err) => {
                return false;
            });

Returns request to http://test.com/user/tokeninfo failed, reason: Nock: No match for request GET http://test.com/user/tokeninfo
I have the feeling it compares all the rest of the headers with it.
By attaching .log(console.log) to the nock I get the following debug information:

matching http://test.com:80 to GET http://test.com:80/user/tokeninfo: true
bodies don't match:
{ reqheaders: { authorization: 'Bearer VALID_JWT' } }

And here the whole stacktrace:
{ Error
at OverriddenClientRequest. (C:\Users\rai\workspace\fsdsfsdfss\node_modules\node-fetch\index.js:133:11)
at emitOne (events.js:96:13)
at OverriddenClientRequest.emit (events.js:188:7)
at C:\Users\rai\workspace\fsdsfsdfss\node_modules\nock\lib\request_overrider.js:206:11
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'FetchError',
message: 'request to http://test.com/user/tokeninfo failed, reason: Nock: No match for request GET http://test.com/user/tokeninfo ',
type: 'system',
errno: undefined,
code: undefined }

@ianaz
Copy link
Author

ianaz commented Nov 29, 2016

Probably duplicate of #748

@stale
Copy link

stale bot commented Sep 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.

@stale stale bot added the stale label Sep 17, 2018
@stale stale bot closed this as completed Sep 24, 2018
@lock
Copy link

lock bot commented Oct 8, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Oct 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant