Skip to content

Commit

Permalink
fix: unordered watchers fix (#584)
Browse files Browse the repository at this point in the history
Fixes 573
  • Loading branch information
eddyerburgh committed May 5, 2018
1 parent 5e02b92 commit db8f393
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/test-utils/src/wrapper.js
Expand Up @@ -537,6 +537,7 @@ export default class Wrapper implements BaseWrapper {

// $FlowIgnore : Problem with possibly null this.vm
this.vnode = this.vm._vnode
orderWatchers(this.vm || this.vnode.context.$root)
}

/**
Expand Down
38 changes: 38 additions & 0 deletions test/specs/wrapper/setProps.spec.js
Expand Up @@ -105,6 +105,44 @@ describeWithShallowAndMount('setProps', (mountingMethod) => {
expect(wrapper.text()).to.equal('There is no message yet')
})

it.only('runs watchers correctly', () => {
const TestComponent = {
template: `<div id="app">
{{ stringified }}
</div>`,
props: ['collection'],
data: () => ({
data: ''
}),
computed: {
stringified () {
return this.collection.join(',')
}
},
watch: {
collection: 'execute'
},
methods: {
execute () {
this.data = this.stringified
}
}
}
const wrapper = mountingMethod(TestComponent, {
propsData: { collection: [] }
})
expect(wrapper.vm.stringified).to.equal('')
expect(wrapper.vm.data).to.equal('')

wrapper.setProps({ collection: [1, 2, 3] })
expect(wrapper.vm.stringified).to.equal('1,2,3')
expect(wrapper.vm.data).to.equal('1,2,3')

wrapper.vm.collection.push(4, 5)
expect(wrapper.vm.stringified).to.equal('1,2,3,4,5')
expect(wrapper.vm.data).to.equal('1,2,3,4,5')
})

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 db8f393

Please sign in to comment.