diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index c898222f3..f5a7e8321 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -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' @@ -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.') diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index d4a779c05..aa1b0f7bf 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -113,6 +113,7 @@ describeWithMountingMethods('options.slots', (mountingMethod) => { const wrapper5 = mountingMethod(ComponentWithSlots, { slots: { default: '1{{ foo }}2' }}) expect(wrapper5.find('main').html()).to.equal('
1bar2
') wrapper5.trigger('keydown') + expect(wrapper5.find('main').html()).to.equal('
1BAR2
') const wrapper6 = mountingMethod(ComponentWithSlots, { slots: { default: '

1

2

' }}) expect(wrapper6.find('main').html()).to.equal('

1

2

') const wrapper7 = mountingMethod(ComponentWithSlots, { slots: { default: '1

2

3' }}) diff --git a/test/specs/mounting-options/sync.spec.js b/test/specs/mounting-options/sync.spec.js index d387351e0..7651f28cb 100644 --- a/test/specs/mounting-options/sync.spec.js +++ b/test/specs/mounting-options/sync.spec.js @@ -46,7 +46,7 @@ describeWithShallowAndMount('options.sync', (mountingMethod) => {
computed.text: {{ computedText }}
- + `, data () { return {