Skip to content

Instantly share code, notes, and snippets.

@ChuckJHardy
Created March 22, 2019 22:23
Show Gist options
  • Save ChuckJHardy/be6819959c345548bc91d45d5fa7282c to your computer and use it in GitHub Desktop.
Save ChuckJHardy/be6819959c345548bc91d45d5fa7282c to your computer and use it in GitHub Desktop.
Typescript LocalStorage Mock
const localStorageMock = (() => {
let store: IDict = {};
return {
getItem(key: any) {
return store[key] || null;
},
setItem(key: any, value: any) {
store[key] = value.toString();
},
removeItem(key: any) {
delete store[key];
},
clear() {
store = {};
},
};
})();
Object.defineProperty(window, "localStorage", {
value: localStorageMock,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment