From c095221a3a05595a4f49aaeda5e7d2e888b9e092 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Tue, 9 Jan 2018 19:53:59 +0000 Subject: [PATCH] fix: run watchers before updating component --- src/wrappers/vue-wrapper.js | 6 +-- test/unit/specs/TransitionGroupStub.spec.js | 33 ------------- .../components/TransitionGroupStub.spec.js | 49 +++++++++++++++++++ .../{ => components}/TransitionStub.spec.js | 0 4 files changed, 52 insertions(+), 36 deletions(-) delete mode 100644 test/unit/specs/TransitionGroupStub.spec.js create mode 100644 test/unit/specs/components/TransitionGroupStub.spec.js rename test/unit/specs/{ => components}/TransitionStub.spec.js (100%) diff --git a/src/wrappers/vue-wrapper.js b/src/wrappers/vue-wrapper.js index 06ccc8207..925e79822 100644 --- a/src/wrappers/vue-wrapper.js +++ b/src/wrappers/vue-wrapper.js @@ -12,12 +12,12 @@ function update () { if (this.$_mountingOptionsSlots) { addSlots(this, this.$_mountingOptionsSlots) } - const vnodes = this._render() - this._update(vnodes) - this.$children.forEach(child => update.call(child)) this._watchers.forEach(watcher => { watcher.run() }) + const vnodes = this._render() + this._update(vnodes) + this.$children.forEach(child => update.call(child)) } export default class VueWrapper extends Wrapper implements BaseWrapper { diff --git a/test/unit/specs/TransitionGroupStub.spec.js b/test/unit/specs/TransitionGroupStub.spec.js deleted file mode 100644 index 65dbfd39f..000000000 --- a/test/unit/specs/TransitionGroupStub.spec.js +++ /dev/null @@ -1,33 +0,0 @@ -import ComponentWithTransitionGroup from '~resources/components/component-with-transition-group.vue' -import TransitionGroupStub from '~src/components/TransitionGroupStub' -import { mount } from '~vue-test-utils' - -describe('TransitionGroupStub', () => { - it('update synchronously when used as stubs for Transition', () => { - const wrapper = mount(ComponentWithTransitionGroup, { - stubs: { - 'transition-group': TransitionGroupStub - } - }) - expect(wrapper.text()).contains('a') - wrapper.setData({ a: 'b' }) - expect(wrapper.text()).contains('b') - }) - - // it('logs error when has multiple children', () => { - // const TestComponent = { - // template: ` - //
- // ` - // } - // const msg = '[vue-test-utils]: can only be used on a single element. Use for lists.' - // const error = sinon.stub(console, 'error') - // mount(TestComponent, { - // stubs: { - // 'transition': TransitionStub - // } - // }) - // expect(error.args[0][0]).to.equal(msg) - // error.restore() - // }) -}) diff --git a/test/unit/specs/components/TransitionGroupStub.spec.js b/test/unit/specs/components/TransitionGroupStub.spec.js new file mode 100644 index 000000000..b1f071bae --- /dev/null +++ b/test/unit/specs/components/TransitionGroupStub.spec.js @@ -0,0 +1,49 @@ +import ComponentWithTransitionGroup from '~resources/components/component-with-transition-group.vue' +import TransitionGroupStub from '~src/components/TransitionGroupStub' +import { mount } from '~vue-test-utils' + +describe('TransitionGroupStub', () => { + it('update synchronously when used as stubs for Transition', () => { + const wrapper = mount(ComponentWithTransitionGroup, { + stubs: { + 'transition-group': TransitionGroupStub + } + }) + expect(wrapper.text()).contains('a') + wrapper.setData({ a: 'b' }) + expect(wrapper.text()).contains('b') + }) + + it('updates watchers', () => { + const TestComponent = { + data: () => ({ + someWatchedData: null, + someData: null + }), + watch: { + someWatchedData (newData) { + console.log('asd') + this.someData = newData + } + }, + template: ` + + {{someData}} + + ` + } + const wrapper = mount(TestComponent, { + stubs: { + 'transition-group': TransitionGroupStub + } + }) + wrapper.setData({ + someWatchedData: 'some data' + }) + expect(wrapper.html()).contains('some data') + }) +}) diff --git a/test/unit/specs/TransitionStub.spec.js b/test/unit/specs/components/TransitionStub.spec.js similarity index 100% rename from test/unit/specs/TransitionStub.spec.js rename to test/unit/specs/components/TransitionStub.spec.js