test(web): keep localStorage polyfill in vitest setup (required — jsdom has no localStorage here)
This commit is contained in:
parent
1051ecdc5b
commit
b1cb04747e
1 changed files with 23 additions and 0 deletions
|
|
@ -1 +1,24 @@
|
||||||
import "@testing-library/jest-dom/vitest";
|
import "@testing-library/jest-dom/vitest";
|
||||||
|
|
||||||
|
// Polyfill localStorage for jsdom if not available
|
||||||
|
if (typeof localStorage === "undefined") {
|
||||||
|
const store: Record<string, string> = {};
|
||||||
|
(global as any).localStorage = {
|
||||||
|
getItem: (key: string) => store[key] || null,
|
||||||
|
setItem: (key: string, value: string) => {
|
||||||
|
store[key] = String(value);
|
||||||
|
},
|
||||||
|
removeItem: (key: string) => {
|
||||||
|
delete store[key];
|
||||||
|
},
|
||||||
|
clear: () => {
|
||||||
|
for (const key in store) {
|
||||||
|
delete store[key];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
key: (index: number) => Object.keys(store)[index] || null,
|
||||||
|
get length() {
|
||||||
|
return Object.keys(store).length;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue