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 doesn't work properly if child component is root of parent component #2300

Closed
ElVisPL opened this issue Jan 15, 2024 · 2 comments · Fixed by #2327
Closed
Labels
bug Something isn't working

Comments

@ElVisPL
Copy link

ElVisPL commented Jan 15, 2024

Describe the bug
This is known issue in vue test utils v1, but the previous workaround doesn't work anymore

<template>
  <WelcomeItem :test="2"> </WelcomeItem>
</template>

vs

<template>
  <div>
    <WelcomeItem :test="2"> </WelcomeItem>
  </div>
</template>

To Reproduce

https://stackblitz.com/edit/github-orekbd?file=src%2Fcomponents%2F__tests__%2FTheWelcome.spec.ts

run yarn test:utils TheWelcome

Expected behavior

findComponent.props() returns props of child component

Related information:

In vue test utils v1 there was workaround:

const childWrapper = createWrapper(wrapper.vm.$children[0])

Now there is no wrapper.vm.$children

@ElVisPL ElVisPL added the bug Something isn't working label Jan 15, 2024
@cexbrayat
Copy link
Member

This is strange indeed. Would you be able to look into it and open a PR?

@freakzlike
Copy link
Collaborator

Instead of using the tag name wrapper.findComponent('welcome-item-stub') you can use the component name wrapper.findComponent({ name: 'WelcomeItem' }) which correctly returns the props of the component.

I guess the selector does not correctly resolve the component. Therefore the props are not treated correctly and instead returned by .attributes(). I will try to investigate the code, when I got some time

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

Successfully merging a pull request may close this issue.

3 participants