Spy function into computed get

Viewed 287

I'm trying to spy methods into computed properties :

time() {
  get() {
    let time = this.winLimitByType(this.gameId, this.winLimitType, this.timeRangeIndex)[this.timeType];

    if (time) {
      time = time.slice(0, 5);

      if (this.timeType === TO_TIME) {
        time = this.getRealTimeToDisplay(time);
      }
    }

    return time;
  },

  set(value) {
    ...
  }
}

When I run test :

  const wrapper = factory(WinLimitType.AMOUNT_IN_TIME_SLOTS_DAY,
    OperationObjectGenerator.generateTimeRange('number', '10:00', '11:59:00'), 'toTime');

  const spyGetRealTimeToDisplay = jest.spyOn(wrapper.vm, 'getRealTimeToDisplay');

  wrapper.vm.time;

  expect(spyGetRealTimeToDisplay).toBeCalledWith('11:59');

Got the error :

Expected mock function to have been called with: ["11:59"] But it was not called.

Is there a way to test it ?

Thanks.

0 Answers
Related