Skip to content

Commit

Permalink
fix: update props when watcher depends on value (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Jul 22, 2018
1 parent 2e6de7b commit 2aeaee3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/specs/wrapper/setProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ describeWithShallowAndMount('setProps', mountingMethod => {
.with.property('message', message)
})

it('updates watched prop', () => {
const TestComponent = {
template: '<div />',
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('<div><p></p></div>')
Expand Down

0 comments on commit 2aeaee3

Please sign in to comment.