Skip to content

Commit 8a4bdc2

Browse files
committed
test(localStorageSpec): test cookie dealing with objects and arrays
1 parent 7493cd8 commit 8a4bdc2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/spec/localStorageSpec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,24 @@ describe('localStorageService', function() {
400400
expect(localStorageService.get('cookieKey')).toEqual('');
401401
}));
402402

403+
it('should be able to set and get objects from cookie', inject(function(localStorageService) {
404+
//use as a fallback
405+
localStorageService.set('cookieKey', { a: { b: 1 } });
406+
expect(localStorageService.get('cookieKey')).toEqual({ a: { b: 1 } });
407+
//use directly
408+
localStorageService.cookie.set('cookieKey', { a: 2 });
409+
expect(localStorageService.cookie.get('cookieKey')).toEqual({ a: 2 });
410+
}));
411+
412+
it('should be able to set and get arrays from cookie', inject(function(localStorageService) {
413+
//use as a fallback
414+
localStorageService.set('cookieKey', [1, 2, 3, [ 1, 2, 3 ]]);
415+
expect(localStorageService.get('cookieKey')).toEqual([1, 2, 3, [ 1, 2, 3 ]]);
416+
//use directly
417+
localStorageService.cookie.set('cookieKey', ['foo', 'bar']);
418+
expect(localStorageService.cookie.get('cookieKey')).toEqual(['foo', 'bar']);
419+
}));
420+
403421
Date.prototype.addDays = function(days) {
404422
var date = new Date(this.getTime());
405423
date.setDate(date.getDate() + days);

0 commit comments

Comments
 (0)