How to unit test the checkbox in Angular2

前端 未结 2 1595
北海茫月
北海茫月 2021-02-20 03:05

I have a sample code for checkbox written with Angular2.


    

        
2条回答
  •  清歌不尽
    2021-02-20 03:23

    IS there a need to write fixture.detectChanges()?

    I went through the same test without this and it ends with success. Button 1 is 'checked' by default

      const button1 = debugElement.nativeElement.querySelector(selectorBtn1);
      const button2 = debugElement.nativeElement.querySelector(selectorBtn2);
      ...
      expect(button1.checked).toBeTruthy();
      expect(button2.checked).toBeFalsy();
    
      button2.click();
    
      expect(button1.checked).toBeFalsy();
      expect(button2.checked).toBeTruthy();
      ...
    

提交回复
热议问题