Files
Luke The Dev 4fa4f13558 First Release of Claw3D (#11)
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
2026-03-19 23:14:04 -05:00

45 lines
1.1 KiB
TypeScript

import "@testing-library/jest-dom/vitest";
const ensureLocalStorage = () => {
if (typeof window === "undefined") return;
const existing = window.localStorage as unknown as Record<string, unknown> | undefined;
if (
existing &&
typeof existing.getItem === "function" &&
typeof existing.setItem === "function" &&
typeof existing.removeItem === "function" &&
typeof existing.clear === "function"
) {
return;
}
const store = new Map<string, string>();
const storage = {
get length() {
return store.size;
},
clear() {
store.clear();
},
getItem(key: string) {
return store.has(String(key)) ? store.get(String(key)) ?? null : null;
},
key(index: number) {
return Array.from(store.keys())[index] ?? null;
},
removeItem(key: string) {
store.delete(String(key));
},
setItem(key: string, value: string) {
store.set(String(key), String(value));
},
};
Object.defineProperty(window, "localStorage", {
value: storage,
configurable: true,
});
};
ensureLocalStorage();