From 51f8a14d6885457077cbe8321064c11b8446ccb2 Mon Sep 17 00:00:00 2001 From: 38elements Date: Sat, 26 May 2018 17:08:14 +0900 Subject: [PATCH] add updated hook --- .../test-utils/src/set-watchers-to-sync.js | 14 +++++++++++ test/specs/mounting-options/sync.spec.js | 24 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/test-utils/src/set-watchers-to-sync.js b/packages/test-utils/src/set-watchers-to-sync.js index 93fd85d7a..7577a1515 100644 --- a/packages/test-utils/src/set-watchers-to-sync.js +++ b/packages/test-utils/src/set-watchers-to-sync.js @@ -1,3 +1,5 @@ +import { VUE_VERSION } from './consts' + function setDepsSync (dep) { dep.subs.forEach(setWatcherSync) } @@ -24,4 +26,16 @@ export function setWatchersToSync (vm) { setWatcherSync(vm._watcher) vm.$children.forEach(setWatchersToSync) + + if (!vm.$_vueTestUtils_update) { + vm.$_vueTestUtils_update = vm._update + vm._update = function (vnode, hydrating) { + this.$_vueTestUtils_update(vnode, hydrating) + if (VUE_VERSION >= 2.1 && this._isMounted && this.$options.updated) { + this.$options.updated.forEach((handler) => { + handler.call(this) + }) + } + } + } } diff --git a/test/specs/mounting-options/sync.spec.js b/test/specs/mounting-options/sync.spec.js index d387351e0..7426d1ce4 100644 --- a/test/specs/mounting-options/sync.spec.js +++ b/test/specs/mounting-options/sync.spec.js @@ -1,3 +1,4 @@ +import sinon from 'sinon' import { describeWithShallowAndMount } from '~resources/utils' describeWithShallowAndMount('options.sync', (mountingMethod) => { @@ -46,7 +47,7 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
computed.text: {{ computedText }}
- + `, data () { return { @@ -110,4 +111,25 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => { done() }) }) + + it('call updated when sync is not false', () => { + const spy = sinon.stub() + const TestComponent = { + template: '
{{ foo }}
', + data () { + return { + foo: 'foo' + } + }, + updated () { + spy() + } + } + const wrapper = mountingMethod(TestComponent, { + sync: true + }) + expect(spy.notCalled).to.equal(true) + wrapper.vm.foo = 'bar' + expect(spy.calledOnce).to.equal(true) + }) })