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

This issue has been tracked since 2017-10-05.

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 wrote this answer on 2018-05-27

Kamino cloned this issue to anilanar/moxios

royGil wrote this answer on 2018-09-06

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 wrote this answer on 2020-10-30

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()
})
More Details About Repo
Owner Name axios
Repo Name moxios
Full Name axios/moxios
Language JavaScript
Created Date 2016-05-25
Updated Date 2022-12-05
Star Count 1386
Watcher Count 20
Fork Count 85
Issue Count 19

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date