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

fix(findComponent): allow finding top-level component #1496

Merged
merged 1 commit into from May 20, 2022

Conversation

xanf
Copy link
Collaborator

@xanf xanf commented May 15, 2022

Let's assume following rendering structure:

flowchart LR
    RootComponent:::cmp --> NestedComponent:::cmp --> d(div.someclass):::dom
    classDef cmp fill:blue,color:white;
    classDef dom fill:darkgreen,color:white;

In this case

mount(RootComponent).find('.some-class').find(NestedComponent).exists() // true
mount(RootComponent).find('.some-class').find(RootComponent).exists() // false

This is because __vueParentComponent will point to component who actually rendered dom node
To fix this we traverse ancestors of __vueParentComponent while their vnode.element is equal to current dom node and use resulted vue component as base for our search

* allow finding top-level component when findComponent is chained
from dom node rendered by child
@netlify
Copy link

netlify bot commented May 15, 2022

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 073c355
🔍 Latest deploy log https://app.netlify.com/sites/vue-test-utils-docs/deploys/628129f7402b220008aee3d8
😎 Deploy Preview https://deploy-preview-1496--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@lmiller1990 lmiller1990 merged commit 1e56cc7 into main May 20, 2022
@lmiller1990 lmiller1990 deleted the xanf-fix-nested-component branch May 20, 2022 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants