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

How does one mock axios.all([]) requests? #34

Closed
CallumBrankin opened this issue Oct 5, 2017 · 3 comments
Closed

How does one mock axios.all([]) requests? #34

CallumBrankin opened this issue Oct 5, 2017 · 3 comments

Comments

@CallumBrankin
Copy link

CallumBrankin commented Oct 5, 2017

I'm came across a problem while i was setting up mocking for my project.

I have an axios request that that uses axios.all to make several requests at the same time. Then i thought "how the hell am i going to mock this?".

I'd need to mock about 10 requests to mock the axios.all request, and i don't think that would even work.
Is there functionality to mock an axios.all request?

Update:

I've mocked each request indiviually but is a unefficient and painful process, maybe there's a better way?

@anilanar
Copy link

Kamino cloned this issue to anilanar/moxios

@rGiladi
Copy link

rGiladi commented Sep 6, 2018

if anyone is interested, here is a simple function to handle this

moxios.respondAllWith = function () {
  return Array.from(arguments).reduce((promise, res, i) => {
    return moxios.requests.at(i).respondWith(res)
  }, null)
}

then in your tests

moxios.respondAllWith(
  {
    status: 200,
    response: {}
  },
  {
    status: 200,
    response: {}
  }
).then(() => {
 // done()
})

@automaticdreams
Copy link

Property 'respondAllWith' does not exist on type.....

if anyone is interested, here is a simple function to handle this

moxios.respondAllWith = function () {
  return Array.from(arguments).reduce((promise, res, i) => {
    return moxios.requests.at(i).respondWith(res)
  }, null)
}

then in your tests

moxios.respondAllWith(
  {
    status: 200,
    response: {}
  },
  {
    status: 200,
    response: {}
  }
).then(() => {
 // done()
})

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

No branches or pull requests

5 participants