Mocking Apisauce with axios-mock-adapter
masterWhen using axios-mock-adapter for testing, you must pass the api.axiosInstance to the adapter instead of the global axios instance to ensure the mocks are applied to your Apisauce instance.
import apisauce from 'apisauce'
import MockAdapter from 'axios-mock-adapter'
test('mock adapter', async () => {
const api = apisauce.create("https://api.github.com")
const mock = new MockAdapter(api.axiosInstance)
mock.onGet("/repos/skellock/apisauce/commits").reply(200, {
commits: [{ id: 1, sha: "aef849923444" }],
});
const response = await api.get('/repos/skellock/apisauce/commits')
expect(response.data[0].sha).toEqual("aef849923444")
})