Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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 单元测试Vue计算设置程序_Javascript_Vue.js_Testing_Vue Test Utils - Fatal编程技术网

Javascript 单元测试Vue计算设置程序

Javascript 单元测试Vue计算设置程序,javascript,vue.js,testing,vue-test-utils,Javascript,Vue.js,Testing,Vue Test Utils,我正在使用一个计算的getter和setter来计算和更新我的LocationCredit,就像滑块的值发生变化一样(为了简单起见,省略了它) getter计算要填充滑块的数据,当滑块移动时,它应该使用计算的setter重新计算原始值 然而,在我的测试覆盖范围中,我注意到setter()没有被覆盖。使用setData()可以修改内部数据,但是否可以使用vue test utils测试调用setter export default { props: { ingredient: {

我正在使用一个计算的getter和setter来计算和更新我的LocationCredit,就像滑块的值发生变化一样(为了简单起见,省略了它)

getter计算要填充滑块的数据,当滑块移动时,它应该使用计算的setter重新计算原始值

然而,在我的测试覆盖范围中,我注意到setter()没有被覆盖。使用setData()可以修改内部数据,但是否可以使用vue test utils测试调用setter

export default {
  props: {
    ingredient: {
      type: Object,
      required: true
    }
  },
  computed: {
    calories: {
      get() {
        return this.localIngredient.value * this.localIngredient.caloriesPerGram
      },
      set(amount) {
        this.localIngredient.value = amount / this.localIngredient.caloriesPerGram
      }
    }
  },
  data: () => ({
    localIngredient: {}
  }),
  created() {
    this.localIngredient = this.ingredient
  }
}

理想情况下,滑块应该有一个隐藏的
,用于保存可访问性的值。通过
mount
shallowMount
安装组件后,您可以通过编程方式设置该输入上的值,在下一次勾选后将触发setter方法