насмешливая 'pipe' в тестах jasmine и TypeError: Невозможно прочитать свойство 'pipe' из неопределенного - PullRequest
0 голосов
/ 05 марта 2020

У меня проблема с тестами. Я получаю сообщение об ошибке: TypeError: Cannot read property 'pipe' of undefined

метод в директиве:

@HostListener('mouseenter')
  onMouseenter(): void {
    forkJoin([
      this.dateService.formatDate(dateStart).pipe(take(1)),
      this.dateService.formatDate(dateEnd).pipe(take(1))
    ]).subscribe((dates) => {
      this.showTooltip(`${dates[0]} - ${dates[1]}`);
    });
  }

(formatDate возвращает наблюдаемую строку)

в тесте:

fit('should call mouse enter', () => {
    directive.onMouseenter();
    expect(directive.showTooltip).toHaveBeenCalled();
  });

Должен ли я как-то издеваться над трубой? спасибо!

1 Ответ

0 голосов
/ 05 марта 2020

тест выглядит так

fdescribe('TooltipDirective', () => {
  let directive: TooltipDirective;
  let mockDateService: jasmine.SpyObj<DateService>;

  beforeEach(() => {
    mockDateService = jasmine.createSpyObj('dateService', ['formatDate']);
    directive = new TooltipDirective(null, null, mockDateService);
    directive.tooltipData = {dateStart: new Date(), endDate: Date()};

    spyOn(directive, 'showTooltip');
  });

  fit('should show tooltip', () => {
    directive.onMouseenter();
    expect(directive.showTooltip).toHaveBeenCalled();
  });
});
...