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

Can't find functional component with shallowMount #1813

Closed
Djaler opened this issue Mar 31, 2021 · 8 comments
Closed

Can't find functional component with shallowMount #1813

Djaler opened this issue Mar 31, 2021 · 8 comments
Labels

Comments

@Djaler
Copy link
Contributor

Djaler commented Mar 31, 2021

Subject of the issue

If I mount my component using shallowMount, I can't find functional components inside it.

Steps to reproduce

https://github.com/Djaler/vue-test-utils-functional-components-shallow-mount

  1. Clone repo and install dependencies (npm install)
  2. Run tests (npm run test)

Expected behaviour

Icon component should be found and both tests should pass

Actual behaviour

Icon component not found in both cases

@lmiller1990
Copy link
Member

lmiller1990 commented Apr 6, 2021

I will have to verify but I believe this is a known limitation, at least with Vuetify's functional components, due to how they are composed. This may (or may not) be the case for all functional components, because they do not have an instance (vm) and are just compiled to regular HTML elements.

The way I've generally handled this is using a data-test selector. Another (potential) problem could be shallowMount - since you stub out the VIcon, you are trying to match VIcon component against a stubbed component, not the original VIcon.

Lots of potential issues, I am not sure which one is the cause here.

Potentially related issues:

I have tried to solve this many times before and had no luck, I'm sorry but I don't know if I will be able to look into this one. Vuetify and shallowMount have cost me many hours.

If you find a work-around, please post here so others can benefit. If you find a solution, let me know!

@lmiller1990 lmiller1990 added the bug label Apr 6, 2021
@Djaler
Copy link
Contributor Author

Djaler commented Apr 6, 2021

I found a way how to fix find by component constructor (first case in my example). The cause of the issue was the fact that original VIcon component used in tested component is differ from component imported in test. That's because of strange vuetify setup. (check this commit Djaler/vue-test-utils-functional-components-shallow-mount@b4aa817)

@Djaler
Copy link
Contributor Author

Djaler commented Apr 6, 2021

Also, I have a fix for second case in my example - find component by name. Check this #1817

@Djaler
Copy link
Contributor Author

Djaler commented Apr 7, 2021

Fixed in #1817

@Djaler Djaler closed this as completed Apr 7, 2021
@Djaler
Copy link
Contributor Author

Djaler commented Apr 9, 2021

Can you release this, please?

@lmiller1990
Copy link
Member

lmiller1990 commented Apr 12, 2021

https://github.com/vuejs/vue-test-utils/releases/tag/v1.1.4

Let me know if you have any problems with the release.

@sailod
Copy link

sailod commented Jun 28, 2023

is this fix applied to vue test utils version 2 (for vue3) as well?

@lmiller1990
Copy link
Member

It should work with VTU v2 just fine, please file an issue in that repo if it does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants