Created
October 1, 2019 23:17
-
-
Save joeskeen/1e397f20bcbeeff9af9f2defe9e7f319 to your computer and use it in GitHub Desktop.
A sample spec using a beforeEach block
This file contains hidden or 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
describe('PreferencesService', () => { | |
describe('.getPreference', () => { | |
let service: PreferencesService; | |
let testValue: Observable<string>; | |
let result: Observable<string>; | |
let getItemSpy: jasmine.Spy; | |
beforeEach(() => { | |
testValue = scheduled(['test value'], asapScheduler); | |
getItemSpy = jasmine.createSpy('getItem').and.returnValue(testValue); | |
service = new PreferencesService({ getItem: getItemSpy } as LocalStorage); | |
result = service.getPreference('test key'); | |
}); | |
it('should call getItem from LocalStorage', () => { | |
expect(getItemSpy).toHaveBeenCalled(); | |
}); | |
it('should return the value from LocalStorage', () => { | |
expect(result).toBe(testValue); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment