-
Notifications
You must be signed in to change notification settings - Fork 668
Feature: Allow find
and findAll
to work with tags
#695
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
Comments
I think this is an intuitive way of finding a component, although I'd like to hear what other people think. |
I have a new use case for this. When I stub an external dependency (at work we are using something called const wrapper = shallowMount(Foo, {
stubs: {
flatpickr: true
}
}) I cannot use const wrapper = shallowMount(Foo, {
stubs: {
flatpickr: "<div id='flat' />"
}
}) and const stub = name => ({ name, render: h => h("div" }) or something. We proposed this in an issue a while ago as a helper function, but it would nicer to use something like |
This would also be useful for components like RouterLink that aren't exported by the library that adds them. Currently we include a RouterLinkStub to select a RouterLink, but I don't think this is intuitive: import { RouterLinkStub } from '@vue/test-utils'
const wrapper = mount(TestComponent, {
stubs: {
RouterLink: RouterLinkStub
}
})
wrapper.find(RouterLinkStub) If we selected by tag, you could do this: const wrapper = mount(TestComponent)
wrapper.find('router-link') |
Since the case you mentioned exists in only using |
@38elements I don't think using a css selector (in the case of If |
Passing test is not purpose. |
The RouterLink example is the same with |
I see. |
The PR for this has quite a few conflicts. I can update it, but it might be good to make a decision, be it to include this feature (then I'll need to add more tests) or to not include it, and close the PR, instead of just letting the PR sit forever. |
I think we should implement this, and deprecate constructors as selectors. There are a few benefits:
|
I think existing the tag name is existing the component name. |
I think searching by tag name is definitely more intuitive. One thing I think we need to establish is which
This should simplify
|
There is no constructor option in wrapper page. |
Passing a component matches against the constructor, for example
|
@38elements the big benefit of using tag is to fix the problem of extended child components that will be introduced by this PR—#840. We shouldn't remove any code in the initial PR, but we could add warnings that the consturctor selector will be deprecated in 1.0.0. |
@eddyerburgh |
There is no constructor option in below selector page. |
When I say constructor selector, I mean component selector. |
I commented to this. |
@eddyerburgh |
I'd like to work on this, once we decide it is going to be included! |
Yes please start working on it. I'd like to release it at the same time as I merge #840 |
I am very sorry. |
I'm closing this because this feature would be too complex to implement. We'll continue with the current selector API instead |
What problem does this feature solve?
More intuitive API.
What does the proposed API look like?
There is an open PR to add this API:
Which lets users do
find("tag")
rather thanfind({ name })
orfind(Component)
.There is some objection (see #692 and it's previous PR, #681 ). Here is my thoughts why I like this better than the existing APIs:
name
API:({ name: ... })
doesn't feel very intuitive. We allowquerySelector
like syntax forfind
,({ name })
doesn't conform to this. Also,name
is not always the same as thetag
, and has nothing to do with what is actually rendered, which is whatfind
is used to assert.component
API:find(Component)
is okay, but I don't really like having to import every component I want tofind
to every test. It's just a bunch of boilerplate. It's easy enough to makeshallowMount
andmount
global, in the same waydescribe
is, but this is not an option for components.The least amount of typing and reduced boilerplate is
find({ name })
, but I don't like this that much. If the name is different for the component (it shouldn't be, but it happens) I have to go and find the.vue
file, and check the name. Then if someone else looks at the test, they will likely have the same thought (we are looking for({ name: foo-component })
, but actually this component only renders<bar-component>
).We can still continue to allow for
{ name: 'foo' }
to be used, as well. I am not proposing to remove and existing feature, simply extend it.I don't want to drag this out for too long, if people have too strong an opinion we can just drop it. That's my thoughts.
The text was updated successfully, but these errors were encountered: