Skip to content

Commit

Permalink
fix(setprops): allowed for setProps to be synced with nextTick intervals
Browse files Browse the repository at this point in the history
setProps in certain cases was being blown away by nextTick intervals. If the property is not up to
date, setProps will be called again to sync the changes.

fix #1419
  • Loading branch information
AtofStryker committed Jul 22, 2020
1 parent ef6f166 commit ca56456
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/test-utils/src/wrapper.js
Expand Up @@ -711,7 +711,15 @@ export default class Wrapper implements BaseWrapper {

// $FlowIgnore : Problem with possibly null this.vm
this.vm.$forceUpdate()
return nextTick()
return new Promise((resolve, reject) => {
nextTick().then(() => {
const isUpdated = Object.keys(data).some(key => {
// $FlowIgnore : Problem with possibly null this.vm
return this.vm[key] === data[key]
})
return !isUpdated ? this.setProps(data).then(resolve()) : resolve()
})
})
} catch (err) {
throw err
} finally {
Expand Down
27 changes: 27 additions & 0 deletions test/specs/wrapper/setProps.spec.js
Expand Up @@ -187,6 +187,33 @@ describeWithShallowAndMount('setProps', mountingMethod => {
await wrapper.setProps({ prop1 })
expect(wrapper.vm.prop2).to.equal(prop1)
})

it('invokes watchers with immediate set to "true" when ', async () => {
const callback = sinon.spy()
const TestComponent = {
template: '<div />',
props: ['propA'],
mounted() {
this.$watch(
'propA',
function() {
callback()
},
{ immediate: true }
)
}
}
const wrapper = mountingMethod(TestComponent, {
propsData: { propA: 'none' }
})

expect(callback.calledOnce)
callback.resetHistory()

await wrapper.setProps({ propA: 'value' })
expect(wrapper.props().propA).to.equal('value')
expect(callback.calledOnce)
})
})

it('props and setProps should return the same reference when called with same object', () => {
Expand Down

0 comments on commit ca56456

Please sign in to comment.