Skip to content

Commit d09045a

Browse files
committed
fix vuejs#582
1 parent 51f8a14 commit d09045a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

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

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

33
import Vue from 'vue'
4+
import cloneDeep from 'lodash/cloneDeep'
45
import { addSlots } from './add-slots'
56
import { addScopedSlots } from './add-scoped-slots'
67
import addMocks from './add-mocks'
@@ -92,6 +93,19 @@ export default function createInstance (
9293
addAttrs(vm, options.attrs)
9394
addListeners(vm, options.listeners)
9495

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+
95109
if (options.scopedSlots) {
96110
if (window.navigator.userAgent.match(/PhantomJS/i)) {
97111
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export function setWatchersToSync (vm) {
2727

2828
vm.$children.forEach(setWatchersToSync)
2929

30-
if (!vm.$_vueTestUtils_update) {
31-
vm.$_vueTestUtils_update = vm._update
30+
// preventing double registration
31+
if (!vm.$_vueTestUtils_updateInSetWatcherSync) {
32+
vm.$_vueTestUtils_updateInSetWatcherSync = vm._update
3233
vm._update = function (vnode, hydrating) {
33-
this.$_vueTestUtils_update(vnode, hydrating)
34+
this.$_vueTestUtils_updateInSetWatcherSync(vnode, hydrating)
3435
if (VUE_VERSION >= 2.1 && this._isMounted && this.$options.updated) {
3536
this.$options.updated.forEach((handler) => {
3637
handler.call(this)

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

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ 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>')
116117
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
117118
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
118119
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})

0 commit comments

Comments
 (0)