From 55d7d77f9e927378126b7b97acd5055affde80f5 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Thu, 8 Jul 2021 10:17:02 +1000 Subject: [PATCH 1/2] repro 727 --- tests/mountingOptions/slots.spec.ts | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/mountingOptions/slots.spec.ts b/tests/mountingOptions/slots.spec.ts index 8cf3de3c8..df1cb86c7 100644 --- a/tests/mountingOptions/slots.spec.ts +++ b/tests/mountingOptions/slots.spec.ts @@ -1,6 +1,6 @@ -import { h } from 'vue' +import { defineComponent, h } from 'vue' -import { mount } from '../../src' +import { flushPromises, mount } from '../../src' import Hello from '../components/Hello.vue' import WithProps from '../components/WithProps.vue' import ComponentWithSlots from '../components/ComponentWithSlots.vue' @@ -206,4 +206,32 @@ describe('slots', () => { expect(wrapper.find('span').text()).toBe('Default') expect(wrapper.find('#with-props').text()).toBe('props-msg') }) + + it('triggers child component lifecycles', async () => { + const parentMounted = jest.fn() + const childMounted = jest.fn() + + const Parent = defineComponent({ + mounted() { + parentMounted() + } + }) + + const Child = defineComponent({ + mounted() { + childMounted() + } + }) + + const wrapper = mount(Parent, { + slots: { + default: Child + } + }) + + await flushPromises() + + expect(parentMounted).toHaveBeenCalled() + expect(childMounted).toHaveBeenCalled() + }) }) From 314e005a4315f71d2e5b3a096e9a85795b34c8a5 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Thu, 8 Jul 2021 10:28:08 +1000 Subject: [PATCH 2/2] lint --- src/mount.ts | 2 +- tests/mountingOptions/slots.spec.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 8f7fbd302..45d698795 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -263,7 +263,7 @@ export function mount( function slotToFunction(slot: Slot) { if (typeof slot === 'object') { if ('render' in slot && slot.render) { - return slot.render + return () => h(slot) } if ('template' in slot && slot.template) { diff --git a/tests/mountingOptions/slots.spec.ts b/tests/mountingOptions/slots.spec.ts index df1cb86c7..cf2ec4b6f 100644 --- a/tests/mountingOptions/slots.spec.ts +++ b/tests/mountingOptions/slots.spec.ts @@ -89,7 +89,7 @@ describe('slots', () => { '' + '
' + '
' + - '
' + + '
Hello world
' + '
' + '
' ) @@ -214,16 +214,25 @@ describe('slots', () => { const Parent = defineComponent({ mounted() { parentMounted() + }, + render() { + return h(this.$slots.default!) } }) const Child = defineComponent({ + render() { + return h('span') + }, mounted() { childMounted() } }) const wrapper = mount(Parent, { + global: { + components: { Child } + }, slots: { default: Child }