Created
February 7, 2020 18:01
-
-
Save djpogo/28eb99431d9459180c974b9972bff041 to your computer and use it in GitHub Desktop.
a unit testable 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 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