-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): support persistence of state with camelCase props in the …
…local storage
- Loading branch information
1 parent
d4f1d68
commit 2763f1b
Showing
2 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,46 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { LocalStorageService } from './local-storage.service'; | ||
|
||
describe('LocalStorageService', () => { | ||
let service: LocalStorageService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [LocalStorageService] | ||
}); | ||
service = TestBed.get(LocalStorageService); | ||
}); | ||
|
||
afterEach(() => localStorage.clear()); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should get and set the item', () => { | ||
service.setItem('TEST', 'item'); | ||
expect(service.getItem('TEST')).toBe('item'); | ||
}); | ||
|
||
it('should load initial state', () => { | ||
service.setItem('TEST.PROP', 'value'); | ||
expect(LocalStorageService.loadInitialState()).toEqual({ | ||
test: { prop: 'value' } | ||
}); | ||
}); | ||
|
||
it( | ||
'should be created', | ||
inject([LocalStorageService], (service: LocalStorageService) => { | ||
expect(service).toBeTruthy(); | ||
}) | ||
); | ||
it('should load nested initial state', () => { | ||
service.setItem('TEST.PROP1.PROP2', 'value'); | ||
expect(LocalStorageService.loadInitialState()).toEqual({ | ||
test: { prop1: { prop2: 'value' } } | ||
}); | ||
}); | ||
|
||
it('should load nested initial state with camel case properties and object value', () => { | ||
service.setItem('TEST.PROP.SUB-PROP', 'value'); | ||
expect(LocalStorageService.loadInitialState()).toEqual({ | ||
test: { prop: { subProp: 'value' } } | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters