-
Notifications
You must be signed in to change notification settings - Fork 233
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
fix(findComponent): return root instance if it matches #834
Conversation
Wait, this is a breaking change right? If I want to find the child, not get the same component I am querying from, right? So if we have a const parentWrapper = mount(Parent)
const childWrapper = parentWrapper.findComponent(Child) // what would `childWrapper` be? The Parent or the Child? |
@dobromir-hristov could you please explain a bit. If |
Ah ok, then why did that test fail? The child was different than the parent. Also, how should someone fetch the child component if it's the same as the parent? Like in your recursion example? Just curious. |
it('finds a component when root of mounted component', async () => {
const wrapper = mount(compD)
// make sure it finds the component, not its root
expect(wrapper.findComponent('.c-as-root-on-d').vm).toHaveProperty(
'$options.name',
'ComponentC'
)
}) Here we were mounting component D, which render componentC as it's root: const compD = defineComponent({
name: 'ComponentD',
template: '<comp-c class="c-as-root-on-d" />',
components: { compC }
}) These two obviously share same element and both of them match Regarding your question - how to reach child component - well, if there are no other ways - by calling To be honest, I'm not happy with current behavior - mostly because
|
I agree we should match the V1 behavior - it looks like that's the goal of this PR. Seems ✅ to me - @dobromir-hristov do you have any other concerns/questions? I know you use VTU on some pretty big code bases, do you see any problems? Keep in mind the goal should be V1 compat where-ever possible (even if it doesn't really make sense). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me - will wait on @dobromir-hristov to see if he has any further feedback.
When we're using
findComponent
on recursive component, the result is pretty unexpected - if our selector matches root - it will return first nested instance. Considering #211 I've made sure that if root matches - it always takes priorityThis resulted in failing test which literally expects other behavior. After some consideration and verifying this is behavior of vue-test-utils v1 CodeSandBox - I've dropped offending test intentionally (@dobromir-hristov will be cool if you could look and approve that)