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

Mock a post request with data and query params #88

Closed
DarynHolmes opened this issue Nov 29, 2017 · 2 comments · May be fixed by #130
Closed

Mock a post request with data and query params #88

DarynHolmes opened this issue Nov 29, 2017 · 2 comments · May be fixed by #130

Comments

@DarynHolmes
Copy link

DarynHolmes commented Nov 29, 2017

Firstly: Thanks for the great tool!

Now for my issue:

How can I mock a post request which checks both data and query params?

The production code looks like this:

const getReport = (userId, managerId, start, count, refresh) => {
  return axios.post(url(userId),
    {
      ManagerId: managerId
    }, {
      withCredentials: true,
      start,
      count,
      refresh
    }).then(extractData)
}

The tests I have

      mock.onPost(`http://localhost:3000/example/api/users/${userId}/reports/data`,
        {
          ManagerId: managerId
        }, {
          params: {
            withCredentials: true,
            start,
            count,
            refresh
          }
        }
      ).replyOnce(200, reportGenerator(start, count))

However the params don't seem to matter, I can leave them out, change them, the mock always returns the same data. If I change the body (managerId) then the mock does not return the data, which is what I expect.

How can I mock axios, so that the mocked data is only returned if URL matches, the query params match, and the data match?

Thanks

@bodinsamuel
Copy link

Much needed :)

@ctimmerm
Copy link
Owner

PR here: #130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants