From fccc97014699e6e1166aeee81b1022d6ee17b4a9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 3 Dec 2014 09:40:54 -0300 Subject: [PATCH] add tests localStorage --- js/plugins/LocalStorage.js | 8 ++++++-- test/plugin.localstorage.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/js/plugins/LocalStorage.js b/js/plugins/LocalStorage.js index f60235d10..8e4ee75e3 100644 --- a/js/plugins/LocalStorage.js +++ b/js/plugins/LocalStorage.js @@ -18,11 +18,11 @@ LocalStorage.prototype.init = function() { }; LocalStorage.prototype.setCredentials = function(email, password, opts) { - this.email = email; - this.password = password; + // NOP }; LocalStorage.prototype.getItem = function(k,cb) { + preconditions.checkArgument(_.isFunction(cb)); 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 */ LocalStorage.prototype.createItem = function(name, value, callback) { + preconditions.checkArgument(_.isFunction(callback)); if (this.ls.getItem(name)) { return callback('EEXISTS'); } @@ -37,16 +38,19 @@ LocalStorage.prototype.createItem = function(name, value, callback) { }; LocalStorage.prototype.setItem = function(k,v,cb) { + preconditions.checkArgument(_.isFunction(cb)); this.ls.setItem(k,v); return cb(); }; LocalStorage.prototype.removeItem = function(k,cb) { + preconditions.checkArgument(_.isFunction(cb)); this.ls.removeItem(k); return cb(); }; LocalStorage.prototype.clear = function(cb) { + preconditions.checkArgument(_.isFunction(cb)); this.ls.clear(); return cb(); }; diff --git a/test/plugin.localstorage.js b/test/plugin.localstorage.js index a49e317ce..4e58cae3c 100644 --- a/test/plugin.localstorage.js +++ b/test/plugin.localstorage.js @@ -8,6 +8,7 @@ describe('local storage plugin', function() { beforeEach(function() { storageMock = {}; storageMock.getItem = sinon.stub().returns(VALUE); + storageMock.createItem = sinon.stub().returns(); storageMock.setItem = sinon.stub().returns(); storageMock.removeItem = 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) { storage.removeItem('pepe', function(err) {