I have implemented a computed getter and setter in my code to manage the calculation and updating of my localIngredient variable whenever a slider value changes (details omitted for simplicity).
The getter function is responsible for generating data to display in the slider, and when the slider is adjusted, it should update the original value by utilizing the computed setter.
While reviewing my test coverage, I observed that the setter() function is not being tested. Despite being able to manipulate internal data using setData(), I am curious if vue-test-utils allows for testing the invocation of a 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
}
}