Skip to content

Commit db8f393

Browse files
authoredMay 5, 2018
fix: unordered watchers fix (#584)
Fixes 573
1 parent 5e02b92 commit db8f393

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
 

‎packages/test-utils/src/wrapper.js

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ export default class Wrapper implements BaseWrapper {
537537

538538
// $FlowIgnore : Problem with possibly null this.vm
539539
this.vnode = this.vm._vnode
540+
orderWatchers(this.vm || this.vnode.context.$root)
540541
}
541542

542543
/**

‎test/specs/wrapper/setProps.spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,44 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
105105
expect(wrapper.text()).to.equal('There is no message yet')
106106
})
107107

108+
it.only('runs watchers correctly', () => {
109+
const TestComponent = {
110+
template: `<div id="app">
111+
{{ stringified }}
112+
</div>`,
113+
props: ['collection'],
114+
data: () => ({
115+
data: ''
116+
}),
117+
computed: {
118+
stringified () {
119+
return this.collection.join(',')
120+
}
121+
},
122+
watch: {
123+
collection: 'execute'
124+
},
125+
methods: {
126+
execute () {
127+
this.data = this.stringified
128+
}
129+
}
130+
}
131+
const wrapper = mountingMethod(TestComponent, {
132+
propsData: { collection: [] }
133+
})
134+
expect(wrapper.vm.stringified).to.equal('')
135+
expect(wrapper.vm.data).to.equal('')
136+
137+
wrapper.setProps({ collection: [1, 2, 3] })
138+
expect(wrapper.vm.stringified).to.equal('1,2,3')
139+
expect(wrapper.vm.data).to.equal('1,2,3')
140+
141+
wrapper.vm.collection.push(4, 5)
142+
expect(wrapper.vm.stringified).to.equal('1,2,3,4,5')
143+
expect(wrapper.vm.data).to.equal('1,2,3,4,5')
144+
})
145+
108146
it('throws an error if node is not a Vue instance', () => {
109147
const message = 'wrapper.setProps() can only be called on a Vue instance'
110148
const compiled = compileToFunctions('<div><p></p></div>')

0 commit comments

Comments
 (0)
Please sign in to comment.