ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.44k stars 244 forks source link

Calls in await Promise.all with .map with different params returns same. #276

Open Neeil opened 4 years ago

Neeil commented 4 years ago

I tried to use await Promise.all with .map to call the api with multi different params. And when try to mock the response, the mock replies two same results with different param.

The following is the code and console snips.

I do have such a call in vue stor const dictsData = await Promise.all( //todo: there is something wrong here. names.map(name => { console.log('API:',name) api.DICTDATA_ALL({ page_size: 9999, dict_type: name }) } ) )

And this is my mock handler mock.onAny('/api/dictData/index').reply(config => { console.log('API Mock Data') console.log(query) if (query.dict_id) { let data = getDictData(query.dict_id) if (data != null) { return tools.responseSuccess(data) } else { return tools.responseError() } } else if (query.dict_type) { let data = getDictBytype(query.dict_type) return tools.responseSuccess(data) } }) return requestForMock({ url: '/api/dictData/index', method: 'post', data: query })

The following is the browser log: Snipaste_2020-07-31_14-10-05.png