Skip to content

Instantly share code, notes, and snippets.

@LayZeeDK
Created October 10, 2018 15:30
Show Gist options
  • Save LayZeeDK/f5f80fa60e317a733d845d316c8e0fbd to your computer and use it in GitHub Desktop.
Save LayZeeDK/f5f80fa60e317a733d845d316c8e0fbd to your computer and use it in GitHub Desktop.
Heroes: Observing the heroes$ property of the container component
import { fakeAsync, tick } from '@angular/core/testing';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { HeroService } from '../hero.service';
import { HeroesContainerComponent } from './heroes.container';
describe(HeroesContainerComponent.name, () => {
let container: HeroesContainerComponent;
const destroy: Subject<void> = new Subject();
const heroServiceStub: jasmine.SpyObj<HeroService> = createHeroServiceStub();
const observer: jasmine.Spy = jasmine.createSpy('heroes observer');
beforeEach(fakeAsync(() => {
container = new HeroesContainerComponent(heroServiceStub);
container.heroes$.pipe(takeUntil(destroy)).subscribe(observer);
tick();
}));
afterEach(() => {
destroy.next();
observer.calls.reset();
resetHeroServiceStub(heroServiceStub);
});
afterAll(() => {
destroy.complete();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment