I am about to test some behaviour in a Vue component which only occurs on props change. The Vue component looks similar to this component, the relevant logic for the test happens in the watcher.
<script>
export default {
components: {
},
props: {
examleProp: {
type: Boolean,
required: false,
default: false,
}
},
watch: {
exampleProp: function(newVal, oldVal) {
// logic which needs to be tested
},
}
};
</script>
<template>
<h1>hello world</h1>
</template>
The test logic is running fine when following the below approach.
it('example test', done => {
let wrapper = mount(exampleComponent, {
propsData: {
},
template: `
<example-component >
</example-component>
`
});
wrapper.setProps({
isSubmitting: true
});
});
The watcher is called and ready to be tested, all good.
Since the test is supposed to be integrated in a testsuite, there are some limitations. The component is not mounted but the instance of it like this:
it('example test', done => {
let wrapper = new Vue({
components: {
exampleComponent,
},
template: `
<example-component></example-component>
`,
}).$mount();
// how to update props now?
// wrapper.setProps && wrapper.$setProps are both undefined
});
So what i am trying to achieve is a way to update the props of the instance of an component to trigger the watcher to run, any Ideas on this?
mount()/shallowMount()
be used in that case? – tony19example-component
? – Constantin Groß