-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlocalStorage.test.ts
More file actions
32 lines (27 loc) · 1.03 KB
/
Copy pathlocalStorage.test.ts
File metadata and controls
32 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { afterEach, describe, expect, it, vi } from 'vitest';
afterEach(() => {
localStorage.clear();
vi.resetModules();
});
describe('localStorage helpers', () => {
it('prefixes keys with the OAuth client id', async () => {
// Ensure staging values are used for deterministic keys
Object.defineProperty(window, 'location', {
value: { ...window.location, search: '?staging=true' },
writable: true,
});
await import('./wca-env');
const { localStorageKey } = await import('./localStorage');
expect(localStorageKey('token')).toContain('delegate-dashboard.example-application-id.token');
});
it('sets and retrieves data consistently', async () => {
Object.defineProperty(window, 'location', {
value: { ...window.location, search: '?staging=true' },
writable: true,
});
await import('./wca-env');
const { getLocalStorage, setLocalStorage } = await import('./localStorage');
setLocalStorage('token', 'abc123');
expect(getLocalStorage('token')).toBe('abc123');
});
});