Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
// preventing double registration
if (!vm.$_vueTestUtils_updateInSetWatcherSync) {
vm.$_vueTestUtils_updateInSetWatcherSync = vm._update
vm._update = function (vnode, hydrating) {
this.$_vueTestUtils_updateInSetWatcherSync(vnode, hydrating)
if (VUE_VERSION >= 2.1 && this._isMounted && this.$options.updated) {
this.$options.updated.forEach((handler) => {
handler.call(this)
})
}
}
}
}
37 changes: 36 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,38 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
done()
})
})

it('call updated when sync is not false', () => {
const childComponentSpy = sinon.stub()
const ChildComponent = {
template: '<div>{{ foo }}</div>',
props: ['foo'],
updated () {
childComponentSpy()
}
}
const spy = sinon.stub()
const TestComponent = {
template: '<div>{{ foo }}<child-component :foo="foo" /></div>',
data () {
return {
foo: 'foo'
}
},
updated () {
spy()
}
}
const wrapper = mountingMethod(TestComponent, {
stubs: { 'child-component': ChildComponent },
sync: true
})
expect(spy.notCalled).to.equal(true)
expect(childComponentSpy.notCalled).to.equal(true)
expect(wrapper.html()).to.equal('<div>foo<div>foo</div></div>')
wrapper.vm.foo = 'bar'
expect(spy.calledOnce).to.equal(true)
expect(childComponentSpy.calledOnce).to.equal(true)
expect(wrapper.html()).to.equal('<div>bar<div>bar</div></div>')
})
})