add tests localStorage
This commit is contained in:
parent
5db7695d89
commit
fccc970146
2 changed files with 23 additions and 2 deletions
|
|
@ -18,11 +18,11 @@ LocalStorage.prototype.init = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
LocalStorage.prototype.setCredentials = function(email, password, opts) {
|
||||||
this.email = email;
|
// NOP
|
||||||
this.password = password;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.getItem = function(k,cb) {
|
LocalStorage.prototype.getItem = function(k,cb) {
|
||||||
|
preconditions.checkArgument(_.isFunction(cb));
|
||||||
return cb(null, this.ls.getItem(k));
|
return cb(null, this.ls.getItem(k));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -30,6 +30,7 @@ LocalStorage.prototype.getItem = function(k,cb) {
|
||||||
* Same as setItem, but fails if an item already exists
|
* Same as setItem, but fails if an item already exists
|
||||||
*/
|
*/
|
||||||
LocalStorage.prototype.createItem = function(name, value, callback) {
|
LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||||
|
preconditions.checkArgument(_.isFunction(callback));
|
||||||
if (this.ls.getItem(name)) {
|
if (this.ls.getItem(name)) {
|
||||||
return callback('EEXISTS');
|
return callback('EEXISTS');
|
||||||
}
|
}
|
||||||
|
|
@ -37,16 +38,19 @@ LocalStorage.prototype.createItem = function(name, value, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.setItem = function(k,v,cb) {
|
LocalStorage.prototype.setItem = function(k,v,cb) {
|
||||||
|
preconditions.checkArgument(_.isFunction(cb));
|
||||||
this.ls.setItem(k,v);
|
this.ls.setItem(k,v);
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.removeItem = function(k,cb) {
|
LocalStorage.prototype.removeItem = function(k,cb) {
|
||||||
|
preconditions.checkArgument(_.isFunction(cb));
|
||||||
this.ls.removeItem(k);
|
this.ls.removeItem(k);
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.clear = function(cb) {
|
LocalStorage.prototype.clear = function(cb) {
|
||||||
|
preconditions.checkArgument(_.isFunction(cb));
|
||||||
this.ls.clear();
|
this.ls.clear();
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ describe('local storage plugin', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
storageMock = {};
|
storageMock = {};
|
||||||
storageMock.getItem = sinon.stub().returns(VALUE);
|
storageMock.getItem = sinon.stub().returns(VALUE);
|
||||||
|
storageMock.createItem = sinon.stub().returns();
|
||||||
storageMock.setItem = sinon.stub().returns();
|
storageMock.setItem = sinon.stub().returns();
|
||||||
storageMock.removeItem = sinon.stub().returns();
|
storageMock.removeItem = sinon.stub().returns();
|
||||||
storageMock.clear = sinon.stub().returns();
|
storageMock.clear = sinon.stub().returns();
|
||||||
|
|
@ -25,6 +26,22 @@ describe('local storage plugin', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('#createItem', function(done) {
|
||||||
|
storageMock.getItem = sinon.stub().returns(null);
|
||||||
|
storage.createItem('hola', 'value', function(err) {
|
||||||
|
assert(!err);
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('#createItem (Exists)', function(done) {
|
||||||
|
storage.createItem('hola', 'value', function(err) {
|
||||||
|
err.should.contain('EEXISTS');
|
||||||
|
return done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('#removeItem', function(done) {
|
it('#removeItem', function(done) {
|
||||||
storage.removeItem('pepe', function(err) {
|
storage.removeItem('pepe', function(err) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue