Skip to content

Instantly share code, notes, and snippets.

@masimplo
Created March 15, 2017 09:33
Show Gist options
  • Select an option

  • Save masimplo/a01a83929e9deb53d8a465ebdc3ac6e2 to your computer and use it in GitHub Desktop.

Select an option

Save masimplo/a01a83929e9deb53d8a465ebdc3ac6e2 to your computer and use it in GitHub Desktop.
// 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