-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
46 lines (41 loc) · 1.13 KB
/
Copy pathvitest.setup.ts
File metadata and controls
46 lines (41 loc) · 1.13 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import '@testing-library/jest-dom';
// Node 22+ ships its own `localStorage` global. It shadows jsdom's real Storage
// implementation and has none of the Storage API (getItem/setItem/clear), so any
// code that touches localStorage throws. Replace it with an in-memory Storage.
class MemoryStorage implements Storage {
private store = new Map<string, string>();
get length() {
return this.store.size;
}
clear() {
this.store.clear();
}
getItem(key: string) {
return this.store.get(key) ?? null;
}
key(index: number) {
return [...this.store.keys()][index] ?? null;
}
removeItem(key: string) {
this.store.delete(key);
}
setItem(key: string, value: string) {
this.store.set(key, String(value));
}
}
Object.defineProperty(globalThis, 'localStorage', {
value: new MemoryStorage(),
configurable: true,
writable: true,
});
// jsdom has no ResizeObserver; Radix (RadioGroup, etc.) calls it on mount.
class ResizeObserverStub {
observe() {}
unobserve() {}
disconnect() {}
}
Object.defineProperty(globalThis, 'ResizeObserver', {
value: ResizeObserverStub,
configurable: true,
writable: true,
});