Commit 2dc4e0e9 authored by Jean Rabreau's avatar Jean Rabreau
Browse files

馃毃 changed storage get method fallback

parent 0550446b
......@@ -10,7 +10,7 @@ export default class Storage {
this.storage = storage
}
get(key, fallback=null) {
get(key, fallback= "") {
const value = this.storage.getItem(`${this.prefix}${key}`)
return value ? value : fallback;
}
......@@ -46,7 +46,7 @@ export default class Storage {
// update every property of state from cache
for (const key in state) {
const value = this.get(key)
if (value != null) state[key] = value
if (value !== "") state[key] = value
}
}
}
......
......@@ -15,8 +15,8 @@ describe('Storage class', () => {
it('should retrieve stored value from prefixed key', () => {
expect(storage.get('key')).to.equal('prefixedValue')
})
it('should return null if key not stored', () => {
expect(storage.get('random')).to.be.null
it('should return empty string if key not stored', () => {
expect(storage.get('random')).to.equal("")
})
it('should return fallback if given and key not stored', () => {
expect(storage.get('random', 'des choux')).to.equal('des choux')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment