如何为具有断点观察器的服务编写单元测试?

时间:2020-04-20 16:42:08

标签: angular jasmine karma-jasmine

我有一个带有断点观察器的服务。但是我们如何触发断点观察器覆盖所有分支和行的窗口调整大小事件。

export class BreakPointService {
isSmallDevice ;

  constructor(private breakpointObserver: BreakpointObserver) {
    this.breakpointObserver.observe([`(max-width: 899px)`,
                                    `(min-width: 900px)`])
      .subscribe(result => {

        if (result.matches) {
          if (result.breakpoints[`(max-width: 899px)`]) {
            this.isSmallDevice = true;
          }
          if (result.breakpoints[`(min-width: 900px)`]) {
            this.isSmallDevice = false;
          }
        }
      });
  }
}


0 个答案:

没有答案