diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 63936401f..7c453c7dc 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -674,12 +674,17 @@ export default class Wrapper implements BaseWrapper { } if (this.vm && this.vm._props) { + // Set actual props value this.vm._props[key] = data[key] - } else { // $FlowIgnore : Problem with possibly null this.vm this.vm[key] = data[key] + } else { // $FlowIgnore : Problem with possibly null this.vm.$options this.vm.$options.propsData[key] = data[key] + // $FlowIgnore : Problem with possibly null this.vm + this.vm[key] = data[key] + // $FlowIgnore : Need to call this twice to fix watcher bug in 2.0.x + this.vm[key] = data[key] } }) // $FlowIgnore : Problem with possibly null this.vm diff --git a/test/specs/wrapper/setProps.spec.js b/test/specs/wrapper/setProps.spec.js index fee329a4a..228cc7027 100644 --- a/test/specs/wrapper/setProps.spec.js +++ b/test/specs/wrapper/setProps.spec.js @@ -199,6 +199,24 @@ describeWithShallowAndMount('setProps', mountingMethod => { .with.property('message', message) }) + it('updates watched prop', () => { + const TestComponent = { + template: '
', + props: ['propA'], + mounted () { + this.$watch('propA', function () { + this.propA + }, { immediate: true } + ) + } + } + const wrapper = mountingMethod(TestComponent, { propsData: { propA: 'none' }}) + + wrapper.setProps({ propA: 'value' }) + expect(wrapper.props().propA).to.equal('value') + expect(wrapper.vm.propA).to.equal('value') + }) + it('throws an error if node is not a Vue instance', () => { const message = 'wrapper.setProps() can only be called on a Vue instance' const compiled = compileToFunctions('