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

Change axios config at onGet

Open qkreltms opened this issue 5 years ago • 0 comments

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()

qkreltms avatar Oct 23 '20 08:10 qkreltms