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
When unit testing my ParentComponent I want to check the correct usage of the underlying ChildComponent as well and test its properties. Back in Vue2 I normally did:
It seems two possible workarounds for this behaviour are either:
adding a 1 line comment node above the root element (if using vitest), the root node get treated as a fragment and findComponent() returns child component rather than the wrapper
adding a ref to the root element e.g. <child-component ref="root" ... and accessing the $props and $attrs of the ref in the test, e.g.
Hi,
I have figured it out by now and want to share it:
Testing the child component ChildComponent, which is the root of my component under test, works perfectly via
Subject of the issue
Example:
Lets say I have the following parent component:
When unit testing my ParentComponent I want to check the correct usage of the underlying ChildComponent as well and test its properties. Back in Vue2 I normally did:
I used the
wrapper.vm.$children[0]
approach, becausewrapper.find(ChildComponent)
would return the same wrapper again. (because it is the root)Now my question is: How can I select the child-component in Vue3 to tests its properties?
Steps to reproduce
Tell us how to reproduce this issue. Please provide a working and simplified example.
Expected behaviour
What should happen?
Actual behaviour
What happens instead?
Possible Solution
What are the alternative solutions? Please describe what else you have considered?
The text was updated successfully, but these errors were encountered: