Skip to content

Commit 2aeaee3

Browse files
authored
fix: update props when watcher depends on value (#842)
1 parent 2e6de7b commit 2aeaee3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: packages/test-utils/src/wrapper.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,17 @@ export default class Wrapper implements BaseWrapper {
674674
}
675675

676676
if (this.vm && this.vm._props) {
677+
// Set actual props value
677678
this.vm._props[key] = data[key]
678-
} else {
679679
// $FlowIgnore : Problem with possibly null this.vm
680680
this.vm[key] = data[key]
681+
} else {
681682
// $FlowIgnore : Problem with possibly null this.vm.$options
682683
this.vm.$options.propsData[key] = data[key]
684+
// $FlowIgnore : Problem with possibly null this.vm
685+
this.vm[key] = data[key]
686+
// $FlowIgnore : Need to call this twice to fix watcher bug in 2.0.x
687+
this.vm[key] = data[key]
683688
}
684689
})
685690
// $FlowIgnore : Problem with possibly null this.vm

Diff for: test/specs/wrapper/setProps.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ describeWithShallowAndMount('setProps', mountingMethod => {
199199
.with.property('message', message)
200200
})
201201

202+
it('updates watched prop', () => {
203+
const TestComponent = {
204+
template: '<div />',
205+
props: ['propA'],
206+
mounted () {
207+
this.$watch('propA', function () {
208+
this.propA
209+
}, { immediate: true }
210+
)
211+
}
212+
}
213+
const wrapper = mountingMethod(TestComponent, { propsData: { propA: 'none' }})
214+
215+
wrapper.setProps({ propA: 'value' })
216+
expect(wrapper.props().propA).to.equal('value')
217+
expect(wrapper.vm.propA).to.equal('value')
218+
})
219+
202220
it('throws an error if node is not a Vue instance', () => {
203221
const message = 'wrapper.setProps() can only be called on a Vue instance'
204222
const compiled = compileToFunctions('<div><p></p></div>')

0 commit comments

Comments
 (0)