Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将函数间谍到计算get中_Javascript_Vuejs2_Jestjs_Vue Test Utils - Fatal编程技术网

Javascript 将函数间谍到计算get中

Javascript 将函数间谍到计算get中,javascript,vuejs2,jestjs,vue-test-utils,Javascript,Vuejs2,Jestjs,Vue Test Utils,我试图在计算属性中监视方法: 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.getR

我试图在计算属性中监视方法:

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) {
    ...
  }
}
运行测试时:

  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');
获取错误信息:

预期已使用以下函数调用模拟函数: ["11:59"] 但它没有被称为

有没有办法测试它


谢谢。

您没有调用时间方法。()错过下午时间。应该是wrapper.vm.time()时间是一个计算属性,不缺少()。当我用()调用时,我得到了错误:“wrapper.vm.time不是函数”当我存储wrapper.vm.time的结果时(例如:const result=wrapper.vm.time),我得到了好的结果。但是spy没有附加任何内容。请尝试使用()调用。这是函数jest offer.toHaveBeenCalledWith()是toBeCalledWith()的别名。预期结果相同。