Skip to content

Commit

Permalink
fix #582
Browse files Browse the repository at this point in the history
  • Loading branch information
38elements committed May 27, 2018
1 parent fde1a46 commit 269b7e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/create-instance/create-instance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import Vue from 'vue'
import cloneDeep from 'lodash/cloneDeep'
import { addSlots } from './add-slots'
import { addScopedSlots } from './add-scoped-slots'
import addMocks from './add-mocks'
Expand Down Expand Up @@ -92,6 +93,19 @@ export default function createInstance (
addAttrs(vm, options.attrs)
addListeners(vm, options.listeners)

vm.$_vueTestUtils_mountingOptionsSlots = options.slots
vm.$_vueTestUtils_originalSlots = cloneDeep(vm.$slots)
vm.$_vueTestUtils_originalUpdate = vm._update
vm._update = function (vnode, hydrating) {
// updating slot
if (this.$_vueTestUtils_mountingOptionsSlots) {
this.$slots = cloneDeep(this.$_vueTestUtils_originalSlots)
addSlots(this, this.$_vueTestUtils_mountingOptionsSlots)
vnode = this._render()
}
this.$_vueTestUtils_originalUpdate(vnode, hydrating)
}

if (options.scopedSlots) {
if (window.navigator.userAgent.match(/PhantomJS/i)) {
throwError('the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component.')
Expand Down
6 changes: 3 additions & 3 deletions packages/test-utils/src/set-watchers-to-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export function setWatchersToSync (vm) {

vm.$children.forEach(setWatchersToSync)

if (!vm.$_vueTestUtils_update) {
vm.$_vueTestUtils_update = vm._update
if (!vm.$_vueTestUtils_updateInSetWatcherSync) {
vm.$_vueTestUtils_updateInSetWatcherSync = vm._update
vm._update = function (vnode, hydrating) {
this.$_vueTestUtils_update(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)
Expand Down
1 change: 1 addition & 0 deletions test/specs/mounting-options/slots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }})
expect(wrapper5.find('main').html()).to.equal('<main>1bar2</main>')
wrapper5.trigger('keydown')
expect(wrapper5.find('main').html()).to.equal('<main>1BAR2</main>')
const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '<p>1</p><p>2</p>' }})
expect(wrapper6.find('main').html()).to.equal('<main><p>1</p><p>2</p></main>')
const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1<p>2</p>3' }})
Expand Down

0 comments on commit 269b7e1

Please sign in to comment.