From 7354a44bae904ee3971bd898a62937eac7921c93 Mon Sep 17 00:00:00 2001 From: mwq27 Date: Sat, 2 Nov 2013 09:56:32 -0500 Subject: [PATCH 1/2] Update test.js --- test/spec/test.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/test/spec/test.js b/test/spec/test.js index 08cefc6..42bdad8 100644 --- a/test/spec/test.js +++ b/test/spec/test.js @@ -1,12 +1,25 @@ -describe('Module: LocalStorageModule', function() { - 'use strict'; +describe('Tests functionality of the localStorage module', function(){ + beforeEach(module('LocalStorageModule')); + var ls, store = {}; + beforeEach(inject(function(_localStorageService_){ + ls = _localStorageService_; - // Load the Angular module - beforeEach(module('LocalStorageModule')); + spyOn(ls, 'get').andCallFake(function(key){ + return store[key]; + }); - describe('constants', function() { - it('reads the constants', function() { - expect(true).toBe(true); + spyOn(ls, 'set').andCallFake(function(key, val){ + return store[key] = val + ''; + }); + + spyOn(ls, 'clearAll').andCallFake(function(){ + store = {}; + return store; + }); + })); + + it("Should add a value to my local storage", function(){ + ls.set('test', 'MyTest Value'); + expect(ls.get('test')).toBe('MyTest Value'); }); - }); }); From 650e9b825d14da14103f96b61e6e52062c851999 Mon Sep 17 00:00:00 2001 From: mwq27 Date: Sat, 2 Nov 2013 10:05:44 -0500 Subject: [PATCH 2/2] Update test.js --- test/spec/test.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/spec/test.js b/test/spec/test.js index 42bdad8..714c4da 100644 --- a/test/spec/test.js +++ b/test/spec/test.js @@ -5,11 +5,18 @@ describe('Tests functionality of the localStorage module', function(){ ls = _localStorageService_; spyOn(ls, 'get').andCallFake(function(key){ - return store[key]; + 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){ - return store[key] = val + ''; + if(typeof val === "object"){ + val = angular.toJson(val); + } + return store[key] = val; }); spyOn(ls, 'clearAll').andCallFake(function(){ @@ -21,5 +28,11 @@ 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 obj = { key: 'val' }; + ls.set('object', obj); + var res = ls.get('object'); + expect(res.key).toBe('val'); + }); });