Skip to content

Instantly share code, notes, and snippets.

@joeskeen
Created October 1, 2019 23:17
Show Gist options
  • Save joeskeen/1e397f20bcbeeff9af9f2defe9e7f319 to your computer and use it in GitHub Desktop.
Save joeskeen/1e397f20bcbeeff9af9f2defe9e7f319 to your computer and use it in GitHub Desktop.
A sample spec using a beforeEach block
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