-
Notifications
You must be signed in to change notification settings - Fork 541
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
Passed query
parameters are completely ignored
#2385
Comments
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
I wouldn't mind, but I think I was mostly confusing myself, because I was trying to port some existing Now, I just handle path matching with a callback. This callback receives the path with the potential query attached, so I can just That seems reasonable, compared to implementing an entire new code path for query parameter matching in So, maybe just a small addition to the documentation to mention that the Let me know what you think 😊 |
Would you like to send a PR for it? |
Yeah, I'll try to make it happen this weekend :) |
The behavior of `query` was unclear, as it only applies to the case where `path` is provided as a `string`. It also wasn't clear that the `RegExp` and callback case will receive the query as part of the path. The additional guidance should help with both. To further clarify the use case, an example for the callback scenario was added. Closes: #2385
The behavior of `query` was unclear, as it only applies to the case where `path` is provided as a `string`. It also wasn't clear that the `RegExp` and callback case will receive the query as part of the path. The additional guidance should help with both. To further clarify the use case, an example for the callback scenario was added. Closes: nodejs#2385
Bug Description
When you pass a
query
object tointercept()
it is only respected if the mocked path is of typestring
, otherwise the entirequery
config is silently discarded:undici/lib/mock/mock-interceptor.js
Lines 73 to 81 in 3a77cbb
Thus, setting
query
in these cases has no effect and all requests will be captured, regardless of their search parameters.Reproducible By
Expected Behavior
Only requests that are matched by the query object are mocked. Ideally,
query
would accept a callback function, just like the other options.Logs & Screenshots
Environment
Debian 12, Node 20
Additional context
The text was updated successfully, but these errors were encountered: