axios / moxios

Mock axios requests for testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request:

miljan-aleksic opened this issue · comments

Hi, I'm using Moxios to build a live demo of SPA project and while was able to do so, its not really strightforward.

I would like to request a function similar to stubRequest with a callback.

moxios.stubRequest('/say/hello', request => {
  const data = {} // do your thing
  return {
    status: 200,
    data
  }
})
commented

As a workaround, you can use a getter for response:

moxios.stubRequest('/say/hello', {
  status: 200,
  get response() {
    const data = {/* ... */};
    return data;
  }
});