add tests to plugin.localstorage
This commit is contained in:
parent
bd698257f9
commit
5db7695d89
2 changed files with 69 additions and 8 deletions
56
test/plugin.localstorage.js
Normal file
56
test/plugin.localstorage.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
var LocalStorage = require('../js/plugins/LocalStorage');
|
||||
var assert = require('assert');
|
||||
|
||||
describe('local storage plugin', function() {
|
||||
|
||||
var storage, storageMock, VALUE=123;
|
||||
|
||||
beforeEach(function() {
|
||||
storageMock = {};
|
||||
storageMock.getItem = sinon.stub().returns(VALUE);
|
||||
storageMock.setItem = sinon.stub().returns();
|
||||
storageMock.removeItem = sinon.stub().returns();
|
||||
storageMock.clear = sinon.stub().returns();
|
||||
storage = new LocalStorage({
|
||||
ls: storageMock
|
||||
});
|
||||
});
|
||||
|
||||
it('#getItem', function(done) {
|
||||
storage.getItem('hola', function(err, value) {
|
||||
assert(!err);
|
||||
storageMock.getItem.getCall(0).args[0].should.equal('hola');
|
||||
value.should.equal(VALUE);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('#removeItem', function(done) {
|
||||
storage.removeItem('pepe', function(err) {
|
||||
assert(!err);
|
||||
storageMock.removeItem.getCall(0).args[0].should.equal('pepe');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#setItem', function(done) {
|
||||
storage.setItem('hola', 'chau', function(err) {
|
||||
assert(!err);
|
||||
storageMock.setItem.getCall(0).args[0].should.equal('hola');
|
||||
storageMock.setItem.getCall(0).args[1].should.equal('chau');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#clear', function(done) {
|
||||
storage.clear(function(err) {
|
||||
assert(!err);
|
||||
storageMock.clear.calledOnce.should.equal(true);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue