I'm trying to test this method:
myMethod() {
result$ = combineLatest([observableOne$,observableTwo$]);
result$.subscribe(([one, two]) => {
this.result = one || two;
});
}
ngAfterViewInit() {
this.myMethod();
}
But every time the test fails:
it('should test my method', (): void => {
cmp.result$ = of([true, false]);
cmp.ngAfterViewInit();
expect(cmp.result).toBe(true);
});
The moment i add a setTimeOut everyhing works as expected
it('should test my method', (): void => {
cmp.result$ = of([true, false]);
cmp.ngAfterViewInit();
setTimeout(() => {
expect(cmp.result).toBe(true);
},1000)
});
Are there a solution to test without using the SetTimeOut ?
The problem was directly related the variable that contains the result of the combineLatest "result$" So instead of assiging the result to a variable, i just returned it directly to the method it self this solution works for me: