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

onGet params doesn't seem to be working #138

Open
fterh opened this issue May 23, 2018 · 5 comments
Open

onGet params doesn't seem to be working #138

fterh opened this issue May 23, 2018 · 5 comments

Comments

@fterh
Copy link

fterh commented May 23, 2018

This works:

mock
  .onGet('/mock?address=Singapore')
  .reply(200, {...});

But this returns Request failed with status code 404:

mock
  .onGet('/mock', {params: {address: 'Singapore'}})
  .reply(200, {...});
@thk2b
Copy link

thk2b commented Jun 6, 2018

I don't think you need to explicitly add a params key.

Have you tried the following ?

mock
  .onGet('/mock', {address: 'Singapore'})
  .reply(200, {...});

@jd-carroll
Copy link

@fterh Are you still observing this issue? I believe I am running into a similar issue and was wondering if you ever solved yours.

@jd-carroll
Copy link

jd-carroll commented Jul 17, 2018

I believe this is a duplicate of #116

Can you please verify and close (Note: See this comment)

@sanbornhilland
Copy link

I believe I'm running into this issue and I'm not convinced it's the same as #116. The suggestion on #116 seems to be that it's a v8 bug but the issue I'm running into seems to be that the url matching is not working correctly in this line:

return (isUrlMatching(url, handler[0]) || isUrlMatching(combineUrls(baseURL, url), handler[0])) && isBodyOrParametersMatching(method, body, parameters, handler[1])  && isRequestHeadersMatching(headers, handler[2]);

That line fails before it even has a chance to match parameters, because isUrlMatching doesn't strip out query params.

For example, I think https://foo?bar=baz and https://foo need to be considered as matching. Right now these urls fail isUrlMatching so the line short-circuits and isBodyOrParametersMatching never gets run.

@sanbornhilland
Copy link

sanbornhilland commented Dec 5, 2018

Ahh, okay I figured out my problem. I think this is likely @fterh's problem as well.

I did not realize axios takes a params option so I was composing the URL params myself. This leads to the issue I described above, where the isUrlMatching fails.

For example...

mock
  .onGet('/mock', {params: {address: 'Singapore'}})
  .reply(200, {...});

// This fails
axios.get('/mock?address=Singapore')

// This works
axios.get('/mock', { params: {address: 'Singapore'}}) 

In my opinion, this is a bug in axios-mock-adapter. Passing params in axios is a convenience so it shouldn't be assumed that that is the way it will be used. Both of the axios.get requests above should work.

https://github.com/axios/axios#example

dwtong pushed a commit to dwtong/kaibosh that referenced this issue Jul 11, 2020
Can create scheduled sessions and get scheduled sessions for a
recipient.

API helper now takes query params as a separate argument instead of
including it in the URL path, as it was causing issues with tests:
ctimmerm/axios-mock-adapter#138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants