-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Some stubbed Vuetify components can't be found with find
wrapper method
#1272
Comments
Hey @anthonygore , This is likely something to do with the fact Iirc if you pass a component to A work around would be to pass an object with it('should find v-text-field', () => {
const wrapper = shallowMount(component);
expect(wrapper.find({ name: 'v-text-field' }).exists()).toBe(true);
}); That may work. |
Hey @lmiller1990, I tried your solution and it doesn't work. But, I think you're onto something with the |
Interesting. I recently got asked to help out with a Vuetify project that has |
Champion, thank you. |
Happens to There is currently no way to |
Are you sure? import { VIcon } from "vuetify/lib";
it('should find v-icon', () => {
const wrapper = shallowMount(component);
expect(wrapper.find(VIcon).exists()).toBe(true); // Passes
}); |
Hm, I guess that isn't what prevents me finding I wonder what the common thing that prevents |
I'm having this issue as well in my own library (not using or related to Vuetify). In my jest setup I use Then I've noticed that |
I find it very interesting too that the stub I found is named |
I still don't understand why When stubbing, Seems to me that line 56 could be changed to Testing this out locally did the trick for me. |
As a workaround before I declare my tests I do: ComponentUnderTest.components = Object.assign(Object.create(Vue.options.components), ComponentUnderTest.components || {}); And then the stubs work like a charm EDIT: Looks like I can |
For me, I cant use
|
@aislanmaia I noticed I could find some functional components too - I can't see any common pattern that makes a component unfindable at this point. |
@lmiller1990 I've some progress here, but in the same point 0 again.
The |
It feels like Vuetify is responsible for a lot of problems around One work-around you can try is adding |
Don't work either. It seems that the element isn't there yet, or maybe it never wasn't there in the component at the moment the test is running. |
What if you do If you are using post |
It doesn't accept a parameter like The markup returned show up some Vuetify components marked with the "-stub" in the names. |
I might take (another) look at this one this week. Whoever solves this will be a hero; this issue has plagued us for a while. I have noticed this only happens sometimes, especially in larger projects. Have you had a similar experience? |
@lmiller1990 no similar, because our project is in early stages and not considered big right now. Saying that, this is our first unit tests with Vuetify, and it is disappointing that it not working at all with jest. |
@aislanmaia I just found that removing the . actually solves this. When running the wrapper.html() I saw that the stubs aren't actually divs or similar with classes applied but actually a v-btn-stub element.
|
Regarding Vuetify, what I am currently doing is just using We are exploring better ways to test third party UI components for the Vue 3 integration. |
@aislanmaia Have you tried my workaround above? |
When specifying the components to stub, merge the globally registered components into the locally registered ones. (fix vuejs#1272)
When specifying the components to stub, merge the globally registered components into the locally registered ones. (fix vuejs#1272)
When specifying the components to stub, merge the globally registered components into the locally registered ones. (fix #1272)
Version
1.0.0-beta.29
Reproduction link
https://github.com/anthonygore/vuetify-test
Steps to reproduce
npm i
npm run test:unit
What is expected?
All tests should pass
What is actually happening?
The second test fails as the VTextField component can't be found.
I don't know if this is a Vuetify issue or a Vue Test Utils issue, but some stubbed child components can't be found with the
find
wrapper method when the parent is shallow mounted.It's not just
VTextField
, either,VSelect
also has this problem, while others likeVIcon
work just fine.Update
I think the issue is something to do with how some global components are registered because this works:
Note that I don't need to locally register
VBtn
, justVTextField
...The text was updated successfully, but these errors were encountered: