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
option to specify full url: nock(url).get().reply(200) #1978
Comments
The most straight forward way to parse it is: const {URL} = require('url')
const testUrl = new URL(TEST_URL)
...
nock(testUrl.origin).get(testUrl.pathname).reply(200); But I agree that it would be nice to do the same inside And if it is not going to be supported - there should be an error risen, because now it's silently ignored and intercept is not working :( |
@alexkli I understand where this request comes from, I've been there. But as I've become more knowledgeable on the inner workings of Nock, there are two issues. Unless there were some drastic changes to Nock's API first, I don't think this feature would benefit users. I'm going to close this issue, as there doesn't seem to be an actionable items, however, this discussion can always be continued here or in another issue. |
No offense: Having used nock for quite some time, I have (still) no real idea what that sentence means. I believe the internal nock model is not intuitive at all 😉 Would it not be possible to have
I wouldn't see how this would be a problem... most likely if I am using the absolute variant I have a single URL to nock and don't care about multiple scopes. |
came here to request this too
so then throw an error in the current version, then add full path support for a future major version |
+1 for |
+1 @Alexsey - this method makes no sense because it will not work with query string parameters |
@psytechno604 the node's nock(testUrl.origin).get(testUrl.path).reply(200); And it will include the query string as well. Take a looks in the docs on the diagram at the URL strings and URL objects section |
Feature Request
Allow passing in a complete absolute URL (to be mocked) as a single string. For example:
Context
Currently one has to split the url into hostname and path:
But sometimes you have a complete URL in your test code (for other reasons) and you just want to mock it as is:
I ran into this multiple times and every time I do the following without thinking, just to spend some time figuring out why it does not work (no match for request...):
This would be very intuitive, and nock should do the "hard" work of whatever is necessary internally to mock it.
Alternatives
The only options (afaics) right now are:
Has the feature been requested before?
I did a quick search on issues but couldn't find anything (but it's hard to search for, "url", "only url" has lots of hits). Sorry if it's a duplicate!
If the feature request is accepted, would you be willing to submit a PR?
Maybe
The text was updated successfully, but these errors were encountered: