You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
The problem is that wrapper.findComponent(...) returns a DOMWrapper instead of a VueWrapper for functional components. Those wrappers can't self-inspect using hasMultipleRoots to locate a correct root element.
I tried other shapes of functional components and they always return a DOMWrapper:
Change find so it returns VueWrapper for functional components. Having DOMWrapper returned initially surprised me, but as VueWrapper is assumed to have a Vue instance (componentVM) perhaps a DOMWrapper return is the way to go. This seems to be an important design choice.
Add a new hasMultipleRoots check to DOMWrapper so it can locate and return the parentElement like VueWrapperdoes, hopefully this would be enough to get the right result when fetchingtext(), html()`, etc...
I am leaning towards 2. because 1. is probably a breaking change with a few ramifications.
Describe the bug
The result of
find(MyFunctionalComponent).text()
is incorrect when finding a functional component that is defined as an array.findComponent(Func).element
doesn’t contain theinnerHTML
I expected, it is a whitespaceText {}
node, so text() is empty.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()
orhtml()
check, works as expected.Related information:
Additional context
The text was updated successfully, but these errors were encountered: