Spy on the result of an Observable Subscription with Jasmine

前端 未结 3 941
粉色の甜心
粉色の甜心 2021-01-24 13:22

I am Jasmine unit testing an angular component, which uses Observables. My component has this lifecycle hook that I am testing:

ngOnInit() {
  this.dataService.ge         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-24 13:38

    Did you ever come up with a solution? What about using the jasmine-marbles package and the complete event?

    it('should update chart on new data', () => {
        const obs$ = cold('--a-|');
        spyOn(service, 'getCellOEE').and.returnValue(obs$);
        component.ngOnInit(); 
        obs$.subscribe({
            complete: () => {
                expect(component.updateChart).toHaveBeenCalledWith('a');
            }
        });
    });
    

提交回复
热议问题