From e96a2b243522e0e237b84d6bb8a152bd06dd4a3e Mon Sep 17 00:00:00 2001 From: mwq27 Date: Sun, 3 Nov 2013 10:36:00 -0600 Subject: [PATCH] Added check if stored value is a number to spyOn, since localStorage will store integers as strings. --- test/spec/test.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/spec/test.js b/test/spec/test.js index 714c4da..1a520de 100644 --- a/test/spec/test.js +++ b/test/spec/test.js @@ -1,21 +1,25 @@ describe('Tests functionality of the localStorage module', function(){ beforeEach(module('LocalStorageModule')); - var ls, store = {}; + var ls, store = []; beforeEach(inject(function(_localStorageService_){ ls = _localStorageService_; spyOn(ls, 'get').andCallFake(function(key){ - if(store[key].charAt(0) ==="{" || store[key].charAt(0) === "["){ + if(store[key].charAt(0) === "{" || store[key].charAt(0) === "["){ return angular.fromJson(store[key]); }else{ return store[key]; } + }); spyOn(ls, 'set').andCallFake(function(key, val){ - if(typeof val === "object"){ + if(angular.isObject(val) || angular.isArray(val)){ val = angular.toJson(val); } + if(angular.isNumber(val)){ + val = val.toString(); + } return store[key] = val; }); @@ -26,8 +30,9 @@ describe('Tests functionality of the localStorage module', function(){ })); it("Should add a value to my local storage", function(){ - ls.set('test', 'MyTest Value'); - expect(ls.get('test')).toBe('MyTest Value'); + var n = 234; + ls.set('test', n); + expect(ls.get('test')).toBe('234'); var obj = { key: 'val' }; ls.set('object', obj);