1.0.0-beta.11
https://github.com/iraklisg/vue-test-utils-example
npm installnpm run test or npm run watchThe test should pass
The setProps method does not update the data property
If we mount the component with options (propsData), instead of using the setProps() method, the test will pass green
wrapper = mount(Foo, {
propsData: {
dataFoo: "foo"
}
});
```
From the repo supplied, the component is doing this:
export default {
props: ['dataFoo'],
data() {
return {
foo: this.dataFoo
}
}
};
Since foo is set when the component is created, it is not going to be reset when the prop is updated. It'll be better for you to utilize a computed property or update the data with a watcher, but this does not appear to be an issue with vue-test-utils.
@dennythecoder Hmm, maybe I am missing something here...
I understand that propsData initializes the Vue instance with passed values (so the linked data property foo will be initialized with its value) but I would expect that setProps() will do the same by re-evaluating the Vue component. Besides, from the vue test utils docs:
setProps(props)
Sets Wrapper vm props and forces update.
@iraklisg, Using setProps() does not re-instantiate the component/vm/wrapper. Instead, it's similar to when the component's parent (component or app) modifies the prop value and triggers an update. _Update_ from the documentation appears to be referring to the normal reactivity in Vue.
setProps is found here:
https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/wrapper.js#L495
_forces update_ might be better worded though. I don't see $forceUpdate being called.
Ok @dennythecoder it is clear now, thank you :+1:
hey, after many hours of looking, I got an answer of how to workaround this.
https://stackoverflow.com/a/66029922/12237505
Most helpful comment
@iraklisg, Using
setProps()does not re-instantiate the component/vm/wrapper. Instead, it's similar to when the component's parent (component or app) modifies the prop value and triggers an update. _Update_ from the documentation appears to be referring to the normal reactivity in Vue.setPropsis found here:https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/wrapper.js#L495
_forces update_ might be better worded though. I don't see
$forceUpdatebeing called.