From db8f3935ef7077ce4b8a54534700d18d7092f207 Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sat, 5 May 2018 18:44:31 +0100 Subject: [PATCH] fix: unordered watchers fix (#584) Fixes 573 --- packages/test-utils/src/wrapper.js | 1 + test/specs/wrapper/setProps.spec.js | 38 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 330ee1968..f050c1da3 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -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) } /** diff --git a/test/specs/wrapper/setProps.spec.js b/test/specs/wrapper/setProps.spec.js index 89ab74670..1f7524b4f 100644 --- a/test/specs/wrapper/setProps.spec.js +++ b/test/specs/wrapper/setProps.spec.js @@ -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: `
+ {{ stringified }} +
`, + 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('

')