28 lines
542 B
TypeScript
28 lines
542 B
TypeScript
|
|
import { beforeEach } from "vitest";
|
||
|
|
|
||
|
|
// Mock localStorage
|
||
|
|
const localStorageMock = (() => {
|
||
|
|
let store: Record<string, string> = {};
|
||
|
|
|
||
|
|
return {
|
||
|
|
getItem: (key: string) => store[key] || null,
|
||
|
|
setItem: (key: string, value: string) => {
|
||
|
|
store[key] = value.toString();
|
||
|
|
},
|
||
|
|
removeItem: (key: string) => {
|
||
|
|
delete store[key];
|
||
|
|
},
|
||
|
|
clear: () => {
|
||
|
|
store = {};
|
||
|
|
},
|
||
|
|
};
|
||
|
|
})();
|
||
|
|
|
||
|
|
Object.defineProperty(window, "localStorage", {
|
||
|
|
value: localStorageMock,
|
||
|
|
});
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
localStorageMock.clear();
|
||
|
|
});
|