fix(web): isolate unit test storage (#33021)

This commit is contained in:
Jason Rasmussen authored and Codex committed 2026-11-06 21:35:53 +03:00
1 parent a5678e0d24
commit 57c45dbb72
2 files changed
+32

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
export class MemoryStorage implements Storage {
private items = new Map<string, string>();
get length() {
return this.items.size;
}
key(index: number) {
return [...this.items.keys()][index] ?? null;
}
getItem(key: string) {
return this.items.get(key) ?? null;
}
setItem(key: string, value: string) {
this.items.set(key, value);
}
removeItem(key: string) {
this.items.delete(key);
}
clear() {
this.items.clear();
}
}
+5
View File
@@ -1,5 +1,10 @@
import { MemoryStorage } from '#test/unit/mocks/storage.ts';
import { init } from 'svelte-i18n';
for (const name of ['localStorage', 'sessionStorage']) {
Object.defineProperty(globalThis, name, { value: new MemoryStorage(), configurable: true });
}
beforeAll(async () => {
await init({ fallbackLocale: 'dev' });
});