Closed OliverEvans96 closed 3 months ago
I ran into this issue as well -- I ended up forking the repository and making a change to the isBodyOrParametersMatching
utility function: https://github.com/KindHealth-Holdings/axios-mock-adapter/commit/6793904f9e6a031a4e3bfa439025b08500d1cc8d
I haven't battle tested it much just yet and I'm not 100% satisfied with the implementation, but here's how I've been using it with a POST request matcher using the params
key of the body:
httpMock.onPost(
'https://host.example/path',
{key: 'value', other: 'value', params: {key: 'value'}}
).replyOnce(200, {response: {key: 'value'}})
If you want to try out my fork, you can just do:
yarn add -D https://github.com/KindHealth-Holdings/axios-mock-adapter.git#match-params-on-post
I'll likely be making changes there, so I can't guarantee the stability of that branch, but it may help you get unblocked.
This is now supported in v2.0.0
Hi there,
Thanks for the great package!
Just a quick question - it seems that it's not currently possible to
.reply
or.replyOnce
to a POST request containing specific URL parameters due to the definition ofvar allowedParamsMethods = ["delete", "get", "head", "options"];
hereIs it a general rule that only these HTTP methods should have URL parameters? Is there some other reason for not allowing url parameters in all verbs here? Am I misunderstanding?
Thanks a lot! Oliver