Skip to content

Commit

Permalink
Fix default behaviour for flush method, issue #30
Browse files Browse the repository at this point in the history
  • Loading branch information
tsironis committed Feb 29, 2016
1 parent ceee274 commit f1c2bc8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lockr.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
};

Lockr.flush = function () {
localStorage.clear();
if (Lockr.prefix.length) {
Lockr.keys().forEach(function(key) {
localStorage.removeItem(key);
});
} else {
localStorage.clear();
}
};
return Lockr;

Expand Down
2 changes: 1 addition & 1 deletion lockr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions specs/lockrSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,27 @@ describe('Lockr::Prefixed', function() {
expect(keys).toContain('imaprefixone', 'imaprefixtwo', 'imaprefixthree', 'imaprefixfour');
});

describe('Lockr.flush', function () {
beforeEach(function() {
localStorage.setItem('noprefix', false);
Lockr.set('test', 123);
Lockr.sadd('array', 2);
Lockr.sadd('array', 3);
Lockr.set('hash', {"test": 123, "hey": "whatsup"});
});

it('clears all contents of the localStorage', function () {
var oldContents = Lockr.getAll();
expect(oldContents.length).not.toBe(0);

expect(Object.keys(localStorage)).toContain('noprefix')
Lockr.flush();
expect(Object.keys(localStorage)).toContain('noprefix')

var contents = Lockr.getAll();
expect(contents.length).toBe(0);
});
});


});

0 comments on commit f1c2bc8

Please sign in to comment.