ctimmerm / axios-mock-adapter

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

Change axios config at onGet #288

Open qkreltms opened 4 years ago

qkreltms commented 4 years ago

It will be good if we can change axios config at onGet, onPost, or etc, like

mock.onGet('/testPreviewImage', undefined, undefined, { baseURL: 'test' } ).reply((request) => [200, testPreviewImage])

When you initialize MockAdapter like this:

const mock = new MockAdapter(axios, { delayResponse: 500 })

mock.onGet('/testPreviewImage').reply((request) => [200, testPreviewImage])

mock.onAny().passThrough()

You should change axios config like this:

// origin baseURL: // I changed baseURL like: localhost:4000/api
const mock = new MockAdapter(axios, { delayResponse: 500 })

// I changed baseURL liket this: localhost:4000/ in axios2
const mock2 = new MockAdapter(axios2, { delayResponse: 500 })

//You can get image from localhost:4000/api/testPreviewImage
mock.onGet('/testPreviewImage').reply((request) => [200, testPreviewImage])
//Now You can get image from localhost:4000/testPreviewImage
mock2.onGet('/testPreviewImage').reply((request) => [200, testPreviewImage])

mock.onAny().passThrough()
mock2.onAny().passThrough()