Merge pull request #49 from mwq27/master
I just added a few tests for the .get and .set methods.dev
commit
ecea0d0ec4
@ -1,12 +1,38 @@
|
|||||||
describe('Module: LocalStorageModule', function() {
|
describe('Tests functionality of the localStorage module', function(){
|
||||||
'use strict';
|
beforeEach(module('LocalStorageModule'));
|
||||||
|
var ls, store = {};
|
||||||
|
beforeEach(inject(function(_localStorageService_){
|
||||||
|
ls = _localStorageService_;
|
||||||
|
|
||||||
// Load the Angular module
|
spyOn(ls, 'get').andCallFake(function(key){
|
||||||
beforeEach(module('LocalStorageModule'));
|
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"){
|
||||||
|
val = angular.toJson(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');
|
||||||
|
|
||||||
|
var obj = { key: 'val' };
|
||||||
|
ls.set('object', obj);
|
||||||
|
var res = ls.get('object');
|
||||||
|
expect(res.key).toBe('val');
|
||||||
|
|
||||||
describe('constants', function() {
|
|
||||||
it('reads the constants', function() {
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue