-
Notifications
You must be signed in to change notification settings - Fork 663
Description
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:
wrapper = shallowMount(ComponentWithChild)
expect(wrapper.find("child-component").exists()).toBe(true)Which lets users do find("tag") rather than find({ name }) or find(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:
-
nameAPI:({ name: ... })doesn't feel very intuitive. We allowquerySelectorlike syntax forfind,({ name })doesn't conform to this. Also,nameis not always the same as thetag, and has nothing to do with what is actually rendered, which is whatfindis used to assert. -
componentAPI:find(Component)is okay, but I don't really like having to import every component I want tofindto every test. It's just a bunch of boilerplate. It's easy enough to makeshallowMountandmountglobal, in the same waydescribeis, 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.