Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a unit testable localStorage mock
const fakeWindowLocalStorage = {
localStorage: {
data: {},
length: 0,
setItem(name, value) {
this.data[name] = value.toString();
this.length = Object.keys(this.data).length;
},
getItem(name) {
return this.data[name];
},
removeItem(name) {
delete this.data[name];
this.length = Object.keys(this.data).length;
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.