Skip to content

Commit ca56456

Browse files
committed
fix(setprops): allowed for setProps to be synced with nextTick intervals
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
1 parent ef6f166 commit ca56456

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,15 @@ export default class Wrapper implements BaseWrapper {
711711

712712
// $FlowIgnore : Problem with possibly null this.vm
713713
this.vm.$forceUpdate()
714-
return nextTick()
714+
return new Promise((resolve, reject) => {
715+
nextTick().then(() => {
716+
const isUpdated = Object.keys(data).some(key => {
717+
// $FlowIgnore : Problem with possibly null this.vm
718+
return this.vm[key] === data[key]
719+
})
720+
return !isUpdated ? this.setProps(data).then(resolve()) : resolve()
721+
})
722+
})
715723
} catch (err) {
716724
throw err
717725
} finally {

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

+27
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,33 @@ describeWithShallowAndMount('setProps', mountingMethod => {
187187
await wrapper.setProps({ prop1 })
188188
expect(wrapper.vm.prop2).to.equal(prop1)
189189
})
190+
191+
it('invokes watchers with immediate set to "true" when ', async () => {
192+
const callback = sinon.spy()
193+
const TestComponent = {
194+
template: '<div />',
195+
props: ['propA'],
196+
mounted() {
197+
this.$watch(
198+
'propA',
199+
function() {
200+
callback()
201+
},
202+
{ immediate: true }
203+
)
204+
}
205+
}
206+
const wrapper = mountingMethod(TestComponent, {
207+
propsData: { propA: 'none' }
208+
})
209+
210+
expect(callback.calledOnce)
211+
callback.resetHistory()
212+
213+
await wrapper.setProps({ propA: 'value' })
214+
expect(wrapper.props().propA).to.equal('value')
215+
expect(callback.calledOnce)
216+
})
190217
})
191218

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

0 commit comments

Comments
 (0)