Public Access
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.
32 lines
961 B
JavaScript
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();
|
|
});
|
|
});
|