Skip to content

Commit

Permalink
fix: correctly pass component definition as slot mounting option
Browse files Browse the repository at this point in the history
Fixes #727
  • Loading branch information
lmiller1990 authored and cexbrayat committed Jul 8, 2021
1 parent 601b5b3 commit 32f0c3b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
43 changes: 40 additions & 3 deletions tests/mountingOptions/slots.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('slots', () => {
'' +
'<div class="named">' +
'<div id="root">' +
'<div id="msg"></div>' +
'<div id="msg">Hello world</div>' +
'</div>' +
'</div>'
)
Expand Down Expand Up @@ -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()
})
})

0 comments on commit 32f0c3b

Please sign in to comment.