Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #30 from Aftonbladet/issue26_localstorageRemoveItem
Browse files Browse the repository at this point in the history
Localstorage only removes single item, instead of clearing entire cache
  • Loading branch information
Andersos committed Nov 30, 2015
2 parents 878ca0f + 23dbef3 commit da2fb23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/spid-localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function set(key, value, expiresInSeconds) {

function clear(key) {
try {
window.localStorage.clear(key);
window.localStorage.removeItem(key);
} catch(e) {
log.info(e);
}
Expand Down
15 changes: 14 additions & 1 deletion test/spec/spid-localstorage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ describe('SPiD.Localstorage', function() {
assert.isNull(storage.get('test'));
});

it(' clear only clears one key', function () {

var preExistingKey = 'a';
var valueStored = 'foo';
storage.set(preExistingKey, valueStored);

storage.set('b');
storage.clear('b');

var preExistingValueRead = storage.get('a');

assert.equal(valueStored, preExistingValueRead);
});

it(' passing an expires parameter should add expires field that\'s in the future', function() {
var data = {'thought' : 'leader'};
storage.set('test', data, 100);
Expand All @@ -39,5 +53,4 @@ describe('SPiD.Localstorage', function() {
assert.isNull( window.localStorage.getItem('test'));
});


});

0 comments on commit da2fb23

Please sign in to comment.