fix(web): isolate unit test storage (#33021)
This commit is contained in:
1 parent
a5678e0d24
commit
57c45dbb72
2 files changed
+32
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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' });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user