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

allowUnmocked option doesn't work properly for specified paths #1867

Closed
sidx1024 opened this issue Feb 5, 2020 · 2 comments · Fixed by #1877
Closed

allowUnmocked option doesn't work properly for specified paths #1867

sidx1024 opened this issue Feb 5, 2020 · 2 comments · Fixed by #1877
Labels

Comments

@sidx1024
Copy link

sidx1024 commented Feb 5, 2020

What is the expected behavior?
Specified path predicate + allowUnmocked doesn't return mocked response.

What is the actual behavior?
Specified path predicate + allowUnmocked should return mocked response.

Possible solution

How to reproduce the issue

test('match path using regexp with allowUnmocked', function (t) {
  nock('http://www.test-domain.com', {allowUnmocked: true})
    .get(uri => uri.endsWith('predicate'))
    .reply(200, 'Matched predicate');

  axios.get('http://www.test-domain.com/resources/predicate', function(err, res, body) {
    t.type(err, 'null');
    t.equal(res.statusCode, 200);
    t.equal(body, 'Matched predicate');
    t.end();
  });
});

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 11.7.2
Node 12.4.1
TypeScript
@mastermatt
Copy link
Member

From a first look on trying to recreate this, it seem to only be broken when the verb method is provided a callback. Passing a string or regex works as expected.
I'm going to keep looking.

mastermatt added a commit to mastermatt/nock that referenced this issue Feb 7, 2020
When an Interceptor was created with a comparator for the path, the
`matchOrigin` function was comparing the string equivalent of the function
instead of evaluating it.

I'm not a fan of the fact that the function `matchOrigin` is comparing the
pathname, but that's a refactor for another day.

Fixes: nock#1867
mastermatt added a commit to mastermatt/nock that referenced this issue Feb 8, 2020
When an Interceptor was created with a comparator for the path, the
`matchOrigin` function was comparing the string equivalent of the function
instead of evaluating it.

I'm not a fan of the fact that the function `matchOrigin` is comparing the
pathname, but that's a refactor for another day.

Fixes: nock#1867
mastermatt added a commit that referenced this issue Feb 10, 2020
* fix: allowMocked when using a callback for the path

When an Interceptor was created with a comparator for the path, the
`matchOrigin` function was comparing the string equivalent of the function
instead of evaluating it.

I'm not a fan of the fact that the function `matchOrigin` is comparing the
pathname, but that's a refactor for another day.

Fixes: #1867
@nockbot
Copy link
Collaborator

nockbot commented Feb 10, 2020

🎉 This issue has been resolved in version 11.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants