1

Im trying to spy a function of a component. I can spy that but my test code does not invoke the Input setter of this component.

export class CameraComponent implements OnInit {

    liveData: LiveDataModal[];
    @Input('liveData')
    set setLiveData(data: LiveDataModal[]) {
      this.liveData = data;
      this.renderCanvas();
    }
    renderCanvas() {
     // ...
    }

}

describe('CameraComponent', () => {
  it('should re render', () => {
    const fixture = TestBed.createComponent(CameraComponent);
    const component = fixture.componentInstance;
    fixture.detectChanges();

    expect(component).toBeTruthy();
    const renderCanvasSpy = spyOn(component, 'renderCanvas')

    component.liveData = [];
    component.renderCanvas();

    fixture.detectChanges();
    const invokeCount = renderCanvasSpy.calls.count();
    expect(invokeCount).toEqual(2)
    // invokeCount should be to 2 but its 1
  });
})
feyzullahyildiz
  • 456
  • 4
  • 11

0 Answers0