mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
30 lines
827 B
TypeScript
30 lines
827 B
TypeScript
import { axiosMock, mockAxios } from '../mocks/axios';
|
|
|
|
describe('test request interceptor', () => {
|
|
it('tests against specified methods', async () => {
|
|
const axios = mockAxios({
|
|
// only cache post methods
|
|
methods: ['post']
|
|
});
|
|
|
|
const response = await axios.get(axiosMock.url);
|
|
const cacheKey = await axios.generateKey(response.config);
|
|
const cache = await axios.storage.get(cacheKey);
|
|
|
|
expect(cache.state).toBe('empty');
|
|
});
|
|
|
|
it('tests specified methods', async () => {
|
|
const axios = mockAxios({
|
|
// only cache get methods
|
|
methods: ['get']
|
|
});
|
|
|
|
const response = await axios.get(axiosMock.url);
|
|
const cacheKey = await axios.generateKey(response.config);
|
|
const cache = await axios.storage.get(cacheKey);
|
|
|
|
expect(cache.state).toBe('cached');
|
|
});
|
|
});
|