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 8cf3de3c8..cf2ec4b6f 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' @@ -89,7 +89,7 @@ describe('slots', () => { '' + '
' + '
' + - '
' + + '
Hello world
' + '
' + '
' ) @@ -206,4 +206,41 @@ 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() + }, + 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 + } + }) + + await flushPromises() + + expect(parentMounted).toHaveBeenCalled() + expect(childMounted).toHaveBeenCalled() + }) })