bigbuffet-rw/app/soapbox/__mocks__/api.js

21 lines
459 B
JavaScript
Raw Normal View History

import MockAdapter from 'axios-mock-adapter';
2021-09-05 12:07:42 -07:00
const api = jest.requireActual('../api');
2020-06-09 15:05:28 -07:00
let mocks = [];
export const __stub = func => mocks.push(func);
export const __clear = () => mocks = [];
2020-06-09 15:05:28 -07:00
const setupMock = axios => {
const mock = new MockAdapter(axios);
mocks.map(func => func(mock));
};
2021-09-05 12:07:42 -07:00
export const staticClient = api.staticClient;
export default (...params) => {
2021-09-05 12:07:42 -07:00
const axios = api.default(...params);
2020-06-09 15:05:28 -07:00
setupMock(axios);
return axios;
};