mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
* chore: Added default prefix param for web storage * chore: Minor default prefix correction * test: add test Co-authored-by: arthurfiorette <arthur.fiorette@gmail.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
/** @jest-environment jsdom */
|
|
|
|
import { buildWebStorage } from '../../src/storage/web-api';
|
|
import { mockAxios } from '../mocks/axios';
|
|
import { testStorageQuota } from './quota';
|
|
import { testStorage } from './storages';
|
|
|
|
describe('tests web storages', () => {
|
|
testStorage('local-storage', () => buildWebStorage(localStorage));
|
|
testStorage('session-storage', () => buildWebStorage(sessionStorage));
|
|
|
|
testStorageQuota('local-storage', () => localStorage);
|
|
testStorageQuota('session-storage', () => sessionStorage);
|
|
|
|
afterEach(() => {
|
|
localStorage.clear();
|
|
sessionStorage.clear();
|
|
});
|
|
|
|
it('Should use a key prefix by default', async () => {
|
|
const storage = sessionStorage; // does not matter any implementation details
|
|
|
|
storage.setItem('test-key', '1');
|
|
|
|
const axios = mockAxios({
|
|
storage: buildWebStorage(storage)
|
|
});
|
|
|
|
await axios.get('url', {
|
|
id: 'test-key'
|
|
});
|
|
|
|
expect(storage.getItem('test-key')).toBe('1');
|
|
expect(axios.storage.get('test-key')).not.toBe('1');
|
|
});
|
|
});
|