Skip to content

Commit

Permalink
add updated hook
Browse files Browse the repository at this point in the history
  • Loading branch information
38elements committed May 27, 2018
1 parent e9f3305 commit 51f8a14
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/test-utils/src/set-watchers-to-sync.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { VUE_VERSION } from './consts'

function setDepsSync (dep) {
dep.subs.forEach(setWatcherSync)
}
Expand All @@ -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)
})
}
}
}
}
24 changes: 23 additions & 1 deletion test/specs/mounting-options/sync.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sinon from 'sinon'
import { describeWithShallowAndMount } from '~resources/utils'

describeWithShallowAndMount('options.sync', (mountingMethod) => {
Expand Down Expand Up @@ -46,7 +47,7 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
<pre>computed.text: <em>{{ computedText }}</em></pre>
</div>
</div>
</div>
</div>
`,
data () {
return {
Expand Down Expand Up @@ -110,4 +111,25 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
done()
})
})

it('call updated when sync is not false', () => {
const spy = sinon.stub()
const TestComponent = {
template: '<div>{{ foo }}</div>',
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)
})
})

0 comments on commit 51f8a14

Please sign in to comment.