如何编写单元测试来覆盖断点观察者的所有条件?

how to write unit test to cover all the condition of breakpoint observer?

我尝试编写单元测试断点观察器。但阳性条件不包括在内

 isSmallScreen: Observable<BreakpointState> = this.breakpointObserver.observe('(max-width: 767px)');

 openEntityDetailDialog(): void {   
        this.entityCreationComponent.close();
      this.dialogRef = this.dialog.open(HomeBusinessEntityDetail, {
        maxWidth: '767px', disableClose: true
      });
   const dialogSubscription = this.isSmallScreen.subscribe(result => {
    if (result.matches) {
      this.dialogRef.updateSize('100%', '100%');
    } else {
      this.dialogRef.updateSize('560px');
    }
  });
 
  this.dialogRef.afterClosed().subscribe(result => {
    dialogSubscription.unsubscribe();
  });
}

enter image description here

帮我写行单元测试

const dialogSubscription = this.isSmallScreen.subscribe(result => {
    if (result.matches) {
      this.dialogRef.updateSize('100%', '100%');
    } 

提前致谢。

你可以试试这样的

it('should update the dialog size', () => {
     component.isSmallScreen = of({ matches: true });
     const spy: Jasmine.Spy = spyOn(component.dialogRef, 'updateSize'); // considering you have mocked the dialogRef in your test
     component.openEntityDetailDialog();
     expect(spy).toHaveBeenCalledWith('100%', '100%');
});