-
Notifications
You must be signed in to change notification settings - Fork 244
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
findAllComponents() returning the same component twice? #689
Comments
I could not reproduce this: https://github.com/vuejs/vue-test-utils-next/compare/issue-689?expand=1 I don't think we have CSB yet. You could fork this repo, and reproduce it there - that'd be ideal, since then if there is a bug, we have the failing test case. I usually put components for reproductions inside of https://github.com/vuejs/vue-test-utils-next/tree/master/tests/components. You can use |
@lmiller1990 here we go with reproduction it('finds components - demo', () => {
const CompA = {
template: '<div>A</div>'
}
const CompB = {
components: { CompA },
template: '<comp-a />'
}
const RootComponent = {
components: { CompB },
template: '<div><comp-b class="foo" /></div>'
}
const wrapper = mount(RootComponent);
// will return 2
expect(wrapper.findAllComponents('.foo')).toHaveLength(1)
}) Frankly speaking, I'm not sure what is correct answer here While it might look reasonable to have "2" returned, the problem is, that this "2" might become "3" for example - consider IMO it might be great to remove ability to find components by DOM selector in the same way it was done in VTU v1 |
Right - I agree, we should not support finding components via CSS selector. This was deprecated, and should not have been implemented here in the first place, right? |
I don't agree, cause all my unit tests are written using CSS selectors. What if I'm testing a 3rd party library component where I do not have the ability to modify the source code? How does this behavior compare to v1 where it wasn't broken? |
@Giwayume I can't say previous behavior (in VTU v1) was not broken - since multiple components can have same
I believe (please note - I'm not a member of VTU team) that if you're relying on retrieving components from inside of 3rd party component HTML - you're testing implementation details of 3rd party component, which is definitely not the way VTU should encourage people to do. |
It's not so much that I'm testing the functionality of the 3rd party components, but using CSS selectors to interact with them is required in order to test our UI that is built with them. |
I think I don't fully understand how to use CSS selectors with a third party library. Once you select the component using something like |
I also agree we should not support using CSS selectors and encourage terser ones instead where possible. Moreover, |
I think maybe I'm digging into the weeds too much, I don't care so much what
|
^ This feature was removed from V1 intentionally. Can't you just search by passing the component instance?
This doesn't make sense - you should be able to interact with them in the same way a user does, eg by finding the |
Define "finding", because using a CSS selector is how I define "finding". CSS selector or XPath is what integration testing frameworks like Selenium use to simulate what a "user" does. I would say passing in the component instance is "knowing", not "finding". Unit tests should be as unknowing to the internal workings of a component as possible and rely on the external interface (e.g. HTML). |
I don't understand this design that assumes the context of the structure of HTML elements surrounding Vue components is unnecessary. If I use a Vue library to place buttons on the page, findComponent('library-button') is pretty useless cause I could have several different buttons. I'm not going to ref every component just to satisfy a testing framework, tests shouldn't require code modification. |
You could just do I think I mentioned in my post above - but once you find the component, what are you doing with it? Are you trying to access |
Really depends, sometimes that's the case, other times it's checking props or emits. |
Is there a reproduction template for https://codesandbox.io? I'm having trouble finding one.
My component looks something like this:
Test is trying to retrieve all component instances by the custom attribute:
It fails on the length assertion, appears to return the same component twice, even though array controlling the loop has 1 item.
If this problem is not familiar to you, I'd like to know if there's an easy reproduction template so I can sort this out.
The text was updated successfully, but these errors were encountered: