Skip to content

Commit

Permalink
fix(wrapper): fix wrapper.element for component with slot (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
xanf committed May 20, 2022
1 parent 8bb8a93 commit 3c55ab1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/vueWrapper.ts
Expand Up @@ -75,19 +75,11 @@ export class VueWrapper<
// if the subtree is an array of children, we have multiple root nodes
if (subTree.shapeFlag === ShapeFlags.ARRAY_CHILDREN) return true

if (subTree.shapeFlag & ShapeFlags.STATEFUL_COMPONENT) {
if (
subTree.shapeFlag & ShapeFlags.STATEFUL_COMPONENT ||
subTree.shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT
) {
// Component has multiple children or slot with multiple children
if (
subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN ||
subTree.shapeFlag & ShapeFlags.SLOTS_CHILDREN
) {
return true
}

if (subTree.component?.subTree) {
return checkTree(subTree.component.subTree)
}
} else if (subTree.shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT) {
if (subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
return true
}
Expand Down
15 changes: 15 additions & 0 deletions tests/element.spec.ts
Expand Up @@ -24,6 +24,21 @@ describe('element', () => {
expect(wrapper.element.nodeName).toBe('DIV')
})

it('returns the VTU root element when mounting component with slot', () => {
const NestedComponent = defineComponent({
template: `<h1><slot></slot></h1>`
})

const RootComponent = defineComponent({
components: { NestedComponent },
template: `<nested-component>test</nested-component>`
})
const wrapper = mount(RootComponent)

expect(wrapper.element.tagName).toBe('H1')
expect(wrapper.html()).toBe('<h1>test</h1>')
})

it('returns the VTU root element when mounting multiple root nodes', () => {
const wrapper = mount(MultiRootText)

Expand Down

0 comments on commit 3c55ab1

Please sign in to comment.