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(element): return correct element for component which renders other component while passing array of vnodes in default slot #1789

Merged
merged 1 commit into from Oct 3, 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
12 changes: 6 additions & 6 deletions src/vueWrapper.ts
Expand Up @@ -74,19 +74,19 @@ export class VueWrapper<
const checkTree = (subTree: VNode): boolean => {
// 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 ||
subTree.shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT
) {
// Component has multiple children or slot with multiple children
if (subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
return true
}

// We are rendering other component, check it's tree instead
if (subTree.component?.subTree) {
return checkTree(subTree.component.subTree)
}

// Component has multiple children
if (subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
return true
}
}

return false
Expand Down
10 changes: 10 additions & 0 deletions tests/element.spec.ts
Expand Up @@ -105,4 +105,14 @@ describe('element', () => {
'<div>foo</div><div>bar</div><div>baz</div>'
)
})

it('returns correct element for component which renders other component with array of vnodes in default slot', () => {
const Nested = {
template: '<div class="nested-root"><slot></slot></div>'
}
const Root = () => h(Nested, {}, [h('div', {}, 'foo'), h('div', {}, 'bar')])

const wrapper = mount(Root)
expect(wrapper.element.innerHTML).toBe('<div>foo</div><div>bar</div>')
})
})