Bug: findComponent() does not return functional component's content when they are defined as arrays #2568
Open
Description
Describe the bug
The result of find(MyFunctionalComponent).text()
is incorrect when finding a functional component that is defined as an array.
const Func = () => ['abc', 'def'];
const wrapper = mount({
setup() {
return () => [h('div', {}, [h(Func)])];
},
});
expect(wrapper.findComponent(Func).text()).toBe('abcdef'); // FAILS! returns ""
findComponent(Func).element
doesn’t contain theinnerHTML
I expected, it is a whitespaceText {}
node, so text() is empty.- If the functional component has a root element this problem is not present.
wrapper.findComponent(Func).element.parentNode.children[0].textContent
contains the expected answer! Because it manages to reach theHTMLElement
node when invokingchildren
, it skips the empty whitespaceText {}
node.
To Reproduce
https://stackblitz.com/edit/github-f5gb9nta?file=src%2F__tests__%2Ffunctional.spec.ts&view=editor
Expected behavior
Any text()
or html()
check, works as expected.
Related information:
Additional context