Skip to content

Commit a7d0a14

Browse files
committed
fix vuejs#455 and remove code for vuejs#582
1 parent 4952874 commit a7d0a14

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

Diff for: packages/create-instance/create-instance.js

-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @flow
22

33
import Vue from 'vue'
4-
import cloneDeep from 'lodash/cloneDeep'
54
import { addSlots } from './add-slots'
65
import { addScopedSlots } from './add-scoped-slots'
76
import addMocks from './add-mocks'
@@ -93,19 +92,6 @@ export default function createInstance (
9392
addAttrs(vm, options.attrs)
9493
addListeners(vm, options.listeners)
9594

96-
vm.$_vueTestUtils_mountingOptionsSlots = options.slots
97-
vm.$_vueTestUtils_originalSlots = cloneDeep(vm.$slots)
98-
vm.$_vueTestUtils_originalUpdate = vm._update
99-
vm._update = function (vnode, hydrating) {
100-
// updating slot
101-
if (this.$_vueTestUtils_mountingOptionsSlots) {
102-
this.$slots = cloneDeep(this.$_vueTestUtils_originalSlots)
103-
addSlots(this, this.$_vueTestUtils_mountingOptionsSlots)
104-
vnode = this._render()
105-
}
106-
this.$_vueTestUtils_originalUpdate(vnode, hydrating)
107-
}
108-
10995
if (options.scopedSlots) {
11096
if (window.navigator.userAgent.match(/PhantomJS/i)) {
11197
throwError('the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.')

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+
// preventing double registration
30+
if (!vm.$_vueTestUtils_updateInSetWatcherSync) {
31+
vm.$_vueTestUtils_updateInSetWatcherSync = vm._update
32+
vm._update = function (vnode, hydrating) {
33+
this.$_vueTestUtils_updateInSetWatcherSync(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/slots.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
113113
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
114114
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
115115
wrapper5.trigger('keydown')
116-
expect(wrapper5.find('main').html()).to.equal('<main>1BAR2</main>')
117116
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
118117
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
119118
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})

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

+35
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) => {
@@ -110,4 +111,38 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
110111
done()
111112
})
112113
})
114+
115+
it('call updated when sync is not false', () => {
116+
const childComponentSpy = sinon.stub()
117+
const ChildComponent = {
118+
template: '<div>{{ foo }}</div>',
119+
props: ['foo'],
120+
updated () {
121+
childComponentSpy()
122+
}
123+
}
124+
const spy = sinon.stub()
125+
const TestComponent = {
126+
template: '<div>{{ foo }}<child-component :foo="foo" /></div>',
127+
data () {
128+
return {
129+
foo: 'foo'
130+
}
131+
},
132+
updated () {
133+
spy()
134+
}
135+
}
136+
const wrapper = mountingMethod(TestComponent, {
137+
stubs: { 'child-component': ChildComponent },
138+
sync: true
139+
})
140+
expect(spy.notCalled).to.equal(true)
141+
expect(childComponentSpy.notCalled).to.equal(true)
142+
expect(wrapper.html()).to.equal('<div>foo<div>foo</div></div>')
143+
wrapper.vm.foo = 'bar'
144+
expect(spy.calledOnce).to.equal(true)
145+
expect(childComponentSpy.calledOnce).to.equal(true)
146+
expect(wrapper.html()).to.equal('<div>bar<div>bar</div></div>')
147+
})
113148
})

0 commit comments

Comments
 (0)