axios-mock-adapter icon indicating copy to clipboard operation
axios-mock-adapter copied to clipboard

Use Promise in mocked data

Open fdrobidoux opened this issue 2 years ago • 1 comments

I made the mistake of doing this, and it cost me a bunch of time :

mockAxiosAdapter.onGet("/groups")
    .replyOnce(200, Promise.resolve(groups));

Could it be possible to resolve Promises in the transformRequest(data) function in handle_request.js?

Thanks!

fdrobidoux avatar Oct 12 '22 18:10 fdrobidoux

why you don't await the promises before and add to the mock just the returned data?

ali3nnn avatar Jul 25 '23 13:07 ali3nnn

Please use the function based reply or replyOnce in that case.

.replyOnce(async function () {
  return [200, await fetchGroups()]
});

marcbachmann avatar Aug 05 '24 20:08 marcbachmann