I have a component with the following ngOnInit() method:
ngOnInit() {
combineLatest([
this.observable1,
this.observable2
])
.pipe(takeUntil(this.unsubscribe$))
.subscribe(([data1, data2]) => {
this.processData(data1, data2);
});
}
I want to write a test to verify that the processData() method is called.
I tried something like this:
it('should call processData', ()=> {
... make sure each observable1 and observable2 will emit a value
spyOn(component, 'processData');
fixture.detectChanges();
expect(component.processData).toHaveBeenCalled();
}));
expect(component.processData).toHaveBeenCalled() will always return false, it doesn't seem to wait until both observables emit a value.
My question is how to test such code? How to test that a method was called inside a subscribe function of an async rxjs operator?
spyOn(comp, 'observable1').and.returnValue(of('dummy data'))? - Andrei Gătej