ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

Use Promise in mocked data #350

Closed fdrobidoux closed 3 months ago

fdrobidoux commented 2 years ago

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!

ali3nnn commented 1 year ago

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

marcbachmann commented 3 months ago

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

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