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