Files
ToBePlayed-Frontend/src/utils/storage.test.js
T
lobo 89d0b29698 refactor: item 29 cleanup
F16 F17 F18 F19 F20 F21: import polling backs off and pauses in a hidden tab, one date format module, fake timers in the import tests, error codes instead of raw messages, one safe storage wrapper, dead code.
2026-09-30 15:00:47 +02:00

32 lines
961 B
JavaScript

// @vitest-environment jsdom
import {afterEach, describe, expect, it, vi} from 'vitest';
import {storage} from './storage.js';
afterEach(() => {
vi.restoreAllMocks();
localStorage.clear();
});
const blockStorage = () => ['getItem', 'setItem', 'removeItem'].forEach((method) =>
vi.spyOn(Storage.prototype, method).mockImplementation(() => {
throw new DOMException('blocked', 'SecurityError');
}));
describe('storage', () => {
it('reads, writes and removes a value', () => {
storage.set('key', 'value');
expect(storage.get('key')).toBe('value');
storage.remove('key');
expect(storage.get('key')).toBeNull();
});
it('does not throw when localStorage throws, and reads null', () => {
blockStorage();
expect(() => storage.set('key', 'value')).not.toThrow();
expect(() => storage.remove('key')).not.toThrow();
expect(storage.get('key')).toBeNull();
});
});