I want to test a component that uses an asynchronous channel. This is my code:
@Component({ selector: 'test', template: ` <div>{{ number | async }}</div> ` }) class AsyncComponent { number = Observable.interval(1000).take(3) } fdescribe('Async Compnent', () => { let component : AsyncComponent; let fixture : ComponentFixture<AsyncComponent>; beforeEach( async(() => { TestBed.configureTestingModule({ declarations: [ AsyncComponent ] }).compileComponents(); }) ); beforeEach(() => { fixture = TestBed.createComponent(AsyncComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should emit values', fakeAsync(() => { tick(1000); fixture.detectChanges(); expect(fixture.debugElement.query(By.css('div')).nativeElement.innerHTML).toBe('0'); });
But the test failed. Angular does not seem to execute Observable for some reason. What am I missing?
When I try to register an observable using the do statement, I do not see any output in the browser console.
source share