-
-
Notifications
You must be signed in to change notification settings - Fork 736
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
query strings and ordering #82
Comments
You can use a path filtering regexp or function that will be called on every request by using You can then take that chance to reorder the query string if you will. |
That is what I ended up doing. I created a filtering function like below.
|
Closing #82. |
Shouldn't this be in the library? Query strings are pretty common things. |
Agree with @jtremback. |
Something like the body matcher code would be awesome for query params as well. |
👍 to this idea / problem |
@pgte would you be open to something like
If so I can do this |
👍 |
1 similar comment
👍 |
I'm mocking an external ugly API which has a lot of query string stuffs...
which is quite ugly but now, ordering is the problem. As @wejendorp said, marcher like body would be great! 👍 |
👍 |
💯 Any plans on this? |
Nock is currently not query-string aware, but I agree this is annoying. We can either scope.filteringPath(nock.orderQueryString); I'm inclined to support the first option since it's more friendly and I suspect covers most of the cases. |
I also think the first option fits nicer into |
@pgte I agree. |
The way I was imagining, was an extension to the API. Similar to the above proposal for .query() // Allow any query string
.query(true) // Allow any query string
.query(false) // Disallow any query string
.query({key: "value"}) // Match query object This matches up with the superagent syntax used in nock's test suite. In the best case, we could parse the query string from the existing path, and treat that path as a shorthand for .get('/users/1?password=XXX')
.get('/users/1').query({password: "XXX"}) // same result And also imagining .filteringQuery(function(queryObj) {
if (queryObj.password == ...);
}); EDIT: added .query() and .query(false) |
Has anyone started a branch for this? I'm happy to give it a crack, from a first look at the codebase we'd want to extend the scope => intercept function with a In terms of the interface, the best solutions are not gonna be backwards compatible, something like
feels quite nice. |
@kevinhodges I wouldn't want to break backwards compatibility. One way I see this working is if, instead of a string with the path you provide an object like this: var google = nock('http://www.google.com')
.get({
path: '/',
query: {
foo: 'bar',
bar: 'foo'
}
}); this should also work: var google = nock('http://www.google.com')
.get({
path: '/',
query: 'foo=bar&bar=foo'
}); Care to give it a go? |
@pgte what is the news about this issue? Is this implemented? |
It's not implemented. Would appreciate some help here. |
Fixed by #341 |
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! |
I'm having some trouble with query strings. I wish to intercept a path like '/path/load' which can accept multiple parameters, like '?b=123&a=456'. The trouble is that "a" "b" could be in any order (since it'd still be a valid URL). Is there some way I could do parameter matching like the POST request using an object map instead of constructing this string?
The text was updated successfully, but these errors were encountered: