Update test.js

dev
mwq27 11 years ago
parent 7354a44bae
commit 650e9b825d

@ -5,11 +5,18 @@ describe('Tests functionality of the localStorage module', function(){
ls = _localStorageService_; ls = _localStorageService_;
spyOn(ls, 'get').andCallFake(function(key){ 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){ 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(){ 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(){ it("Should add a value to my local storage", function(){
ls.set('test', 'MyTest Value'); ls.set('test', 'MyTest Value');
expect(ls.get('test')).toBe('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');
}); });
}); });