Skip to content

Commit 3c55ab1

Browse files
authored
fix(wrapper): fix wrapper.element for component with slot (#1497)
1 parent 8bb8a93 commit 3c55ab1

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/vueWrapper.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,11 @@ export class VueWrapper<
7575
// if the subtree is an array of children, we have multiple root nodes
7676
if (subTree.shapeFlag === ShapeFlags.ARRAY_CHILDREN) return true
7777

78-
if (subTree.shapeFlag & ShapeFlags.STATEFUL_COMPONENT) {
78+
if (
79+
subTree.shapeFlag & ShapeFlags.STATEFUL_COMPONENT ||
80+
subTree.shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT
81+
) {
7982
// Component has multiple children or slot with multiple children
80-
if (
81-
subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN ||
82-
subTree.shapeFlag & ShapeFlags.SLOTS_CHILDREN
83-
) {
84-
return true
85-
}
86-
87-
if (subTree.component?.subTree) {
88-
return checkTree(subTree.component.subTree)
89-
}
90-
} else if (subTree.shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT) {
9183
if (subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
9284
return true
9385
}

tests/element.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ describe('element', () => {
2424
expect(wrapper.element.nodeName).toBe('DIV')
2525
})
2626

27+
it('returns the VTU root element when mounting component with slot', () => {
28+
const NestedComponent = defineComponent({
29+
template: `<h1><slot></slot></h1>`
30+
})
31+
32+
const RootComponent = defineComponent({
33+
components: { NestedComponent },
34+
template: `<nested-component>test</nested-component>`
35+
})
36+
const wrapper = mount(RootComponent)
37+
38+
expect(wrapper.element.tagName).toBe('H1')
39+
expect(wrapper.html()).toBe('<h1>test</h1>')
40+
})
41+
2742
it('returns the VTU root element when mounting multiple root nodes', () => {
2843
const wrapper = mount(MultiRootText)
2944

0 commit comments

Comments
 (0)