mardi 23 mars 2021

Angular test case variable using not in question

I'm new with angular and have some questions with testing on ismobile method. Below is part of the code on the 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?

Aucun commentaire:

Enregistrer un commentaire