Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wrapper): fix wrapper.element for component with slot #1497

Merged
merged 1 commit into from May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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