Skip to content

Bug: findComponent() does not return functional component's content when they are defined as arrays #2568

Open
@miguelrincon

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 the innerHTML I expected, it is a whitespace Text {} 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 the HTMLElement node when invoking children, it skips the empty whitespace Text {} 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

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions