Skip to content

Commit

Permalink
fix(element): return correct element
Browse files Browse the repository at this point in the history
* return correct element for component which renders other component
while passing array of vnodes in default slot
  • Loading branch information
xanf authored and cexbrayat committed Oct 3, 2022
1 parent e754fd1 commit 6212c2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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>')
})
})

0 comments on commit 6212c2c

Please sign in to comment.