Files
coder/site/src/testHelpers/localstorage.ts
T

23 lines
511 B
TypeScript

export const localStorageMock = () => {
const store = {} as Record<string, string>;
return {
getItem: (key: string): string => {
return store[key];
},
setItem: (key: string, value: string) => {
store[key] = value;
},
clear: () => {
Object.keys(store).forEach((key) => {
delete store[key];
});
},
removeItem: (key: string) => {
delete store[key];
},
};
};
Object.defineProperty(window, "localStorage", { value: localStorageMock() });