首页 > 解决方案 > 角度测试用例变量使用没有问题

问题描述

我是 angular 新手,对 ismobile 方法的测试有一些疑问。以下是 homecompoonent.ts 上的部分代码:

ngOnInit(): void {
    this.mapService.mapLoaded$.subscribe(
      state => {
        this.loadingState = state;
      }
    );
    if (!this.isMobile || this.selectedView === 'map') {
      this.mapService.canLoadMap$.next(true);
    } else { this.mapService.triggerMapLoadedTransition(); }
    this.filterService.canLoadFilter$.next(true);
  }

I am trying to test the partialMapService to return to true when !ismobile but couldn't make it work. here's the code so far:
  fit(`should push a true value in the partialMapService`, () => { 
  !(component.isMobile);
  fixture.detectChanges();
partialMapService.canLoadMap$.subscribe((val) => {
  expect(val).toEqual(true); 
})

});

I'm not sure !(component.isMobile) is not the way to put it there but it's expecting null value which is not correct. what is the right way to test ismobile to return canLoadMap to true?

标签: angulartesting

解决方案


推荐阅读