I'm using vue-test-utils@1.1.3 with jest@26 in order to test my component.
The component gets provide data from a parent, and watches for changes of it.
Parent component injects a computed value. I want to check that the watcher (and functionality it invokes) works as expected.
I wonder how can I perform a change of the mocked data I provide in the test?
// ParentComponent.vue, using the @vue/composition-api plugin + syntax
setup() {
let chosenItems = reactive({ items: [] })
function UpdateItems(items) {
chosenItems.items = [...items]
}
provide(
"userItems",
computed(() => chosenItems.items)
)
return { UpdateItems }
}
// The component I want to test, using options-api syntax
export default {
inject: ["userItems"],
watch: {
"userItems.value": function (items) {
// Do Things...
},
},
}
// The test code for the component
const wrapper = mount(ComponentToTest, {
localVue,
router,
provide: {
userItems() {
return ["mockedItems"]
},
},
})
// And now, after mounting, I want to change the data was provided to test the watcher