Skip to content

Commit 51f8a14

Browse files
committed
add updated hook
1 parent e9f3305 commit 51f8a14

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Diff for: packages/test-utils/src/set-watchers-to-sync.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { VUE_VERSION } from './consts'
2+
13
function setDepsSync (dep) {
24
dep.subs.forEach(setWatcherSync)
35
}
@@ -24,4 +26,16 @@ export function setWatchersToSync (vm) {
2426
setWatcherSync(vm._watcher)
2527

2628
vm.$children.forEach(setWatchersToSync)
29+
30+
if (!vm.$_vueTestUtils_update) {
31+
vm.$_vueTestUtils_update = vm._update
32+
vm._update = function (vnode, hydrating) {
33+
this.$_vueTestUtils_update(vnode, hydrating)
34+
if (VUE_VERSION >= 2.1 && this._isMounted && this.$options.updated) {
35+
this.$options.updated.forEach((handler) => {
36+
handler.call(this)
37+
})
38+
}
39+
}
40+
}
2741
}

Diff for: test/specs/mounting-options/sync.spec.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sinon from 'sinon'
12
import { describeWithShallowAndMount } from '~resources/utils'
23

34
describeWithShallowAndMount('options.sync', (mountingMethod) => {
@@ -46,7 +47,7 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
4647
<pre>computed.text: <em>{{ computedText }}</em></pre>
4748
</div>
4849
</div>
49-
</div>
50+
</div>
5051
`,
5152
data () {
5253
return {
@@ -110,4 +111,25 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
110111
done()
111112
})
112113
})
114+
115+
it('call updated when sync is not false', () => {
116+
const spy = sinon.stub()
117+
const TestComponent = {
118+
template: '<div>{{ foo }}</div>',
119+
data () {
120+
return {
121+
foo: 'foo'
122+
}
123+
},
124+
updated () {
125+
spy()
126+
}
127+
}
128+
const wrapper = mountingMethod(TestComponent, {
129+
sync: true
130+
})
131+
expect(spy.notCalled).to.equal(true)
132+
wrapper.vm.foo = 'bar'
133+
expect(spy.calledOnce).to.equal(true)
134+
})
113135
})

0 commit comments

Comments
 (0)