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

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

Open
miguelrincon opened this issue Dec 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@miguelrincon
Copy link

miguelrincon commented Dec 17, 2024

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

@miguelrincon miguelrincon added the bug Something isn't working label Dec 17, 2024
@miguelrincon miguelrincon changed the title Bug: findComponent() does not return functional component when they are defined as arrays Bug: findComponent() does not return functional component's content when they are defined as arrays Dec 17, 2024
@cexbrayat
Copy link
Member

Hi @miguelrincon

This does look like an issue.
Feel free to open a PR if you feel like it to improve this, all contributions are most welcomed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants