Created
March 15, 2017 09:33
-
-
Save masimplo/a01a83929e9deb53d8a465ebdc3ac6e2 to your computer and use it in GitHub Desktop.
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
| // Actual code | |
| ... | |
| public ngOnInit() { | |
| Observable.interval(3000) | |
| .takeUntil(this._componentDestroyed) | |
| .subscribe(() => this._statusStore.refreshStatus()); | |
| } | |
| // Test Code | |
| import { fakeAsync, tick, discardPeriodicTasks } from '@angular/core/testing'; | |
| ... | |
| it('polls statusStore.refreshStatus on an interval', fakeAsync(() => { | |
| spyOn(mockStatusStore, 'refreshStatus').and.callThrough(); | |
| sut.ngOnInit(); | |
| expect(mockStatusStore.refreshStatus).not.toHaveBeenCalled(); | |
| tick(3001); | |
| expect(mockStatusStore.refreshStatus).toHaveBeenCalled(); | |
| tick(3001); | |
| expect(mockStatusStore.refreshStatus).toHaveBeenCalledTimes(2); | |
| discardPeriodicTasks(); | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment