Created
March 22, 2019 22:23
-
-
Save ChuckJHardy/be6819959c345548bc91d45d5fa7282c to your computer and use it in GitHub Desktop.
Typescript LocalStorage Mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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