2021-09-19 19:29:05 -03:00

32 lines
763 B
TypeScript

import { AxiosCacheInstance, CacheProperties, createCache } from '../../src';
import CacheInstance from '../../src/axios/types';
export const axiosMock = {
statusCode: 200,
statusText: '200 Intercepted'
};
export function mockAxios(
options?: Partial<CacheInstance> & Partial<CacheProperties>
): AxiosCacheInstance {
const axios = createCache({
// Defaults to cache every request
...options
});
// Axios interceptors are a stack, so apply this after the cache interceptor
axios.interceptors.request.use((config) => {
config.adapter = async (config) => ({
data: true,
status: axiosMock.statusCode,
statusText: axiosMock.statusText,
headers: {},
config
});
return config;
});
return axios;
}