-
Notifications
You must be signed in to change notification settings - Fork 668
Default props are set as attributes when mounting a stubbed component #1442
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 agree with you @horyd . If I upgraded my version of a dependency, which added some attributes, I wouldn't expect my tests to fail as I haven't changed how I interact with the components in that dependency. Not to mention, some components have a lot of attributes. So seeing them all is quite verbose. |
I'm reworking the stubbing logic for the next version of VTU - which also is aiming to support Vue 3. I am not sure how many of these fixes will be back ported to Vue 2's support, though. Not sure we need more breaking changes. Anyway, For context of other readers, the output is
And the usage is I'm not convinced we should show props passed by the user, but not default props - I think Interesting in @dobromir-hristov @JessicaSachs and @afontcu 's opinions, since this is something I think we need to define before making any more changes. The docs should also reflect this, with some examples. |
I'm in favor of this 👍 – I would not show any prop/attribute from the stubbed out component, as the stub should be a simple placeholder to speed up the test or avoid a more complex test setup. |
Is this a problem of VTU actually? Doing |
The following assertion does pass though |
Hm. Do you think it should pass through @horyd ? I'm in favor of making stubs truly "stubs" and literally just a shell that has no props, attrs etc. Now is a good chance to make these changes since Vue 3 is in alpha and we can potential add something to the codebase to make VTU better. |
This adjustment to props: Object.keys(componentOptions.props || {}).reduce((p, k) => {
p[k] = { type: componentOptions.props[k].type }
return p;
}, {}) Overall though I think that I would prefer it for VTU to retain the attributes and handlers passed to stubs. The reason behind this is that, often enough, there can be thin component abstractions over basic HTML nodes. Take for instance an Another neat thing with the current stubbing logic is that you can do this on something like the vue-material button that implements it's own click handler (and therefore cannot be accessed with Wrapping up, imo, the act of passing certain props from the component being tested to its child components can often encapsulate logic that is not unreasonable to desire testing coverage on. |
Ah, but I do think that the |
Great ideas and discussion all. I have some thoughts about
I'm not sure this is really a good practice or something VTU should encourage. If you want to test a form is disabled, to me, it would make the most sense to click the submit button, and verify that the form submission logic did not trigger, no? For forms in general, it makes way more sense to me to just use
I think we need to rethink this, too, I think. This particular example feels pretty close to testing a implementation detail, instead of the public API. I don't think
I don't have an informed opinion on snapshots - I don't use them. Either way, the generated DOM come from Vue, not VTU - all VTU does is call No right answers, just some food for thought. We need to make some big changes to support Vue 3, and in doing so, have a chance to rethink the API and improve the DX. |
Maybe, but there are so many cases where the public API of the child components is more than enough to indicate user actions, without the overhead of mounting (and the difficulty of finding the element you're looking for in mounted wrappers and other potential side effects of
Because I'm not interested in any interference by child components and their internal logic when I'm focussing on testing its parent component.
If you consider components as first-class citizens then they're really no different from any given DOM element which you can
Unless I'm mistaken, the distinction between default and regular props are lost at the point where the DOM is serialised. It's within the domain of VTU to choose how and what to stub right? I'm coming into Vue from React, where Enzyme is a reasonably mature testing utility. You can see in that example also how the components |
What kind of interactivity does Enzyme give you for stubs? Regarding the snapshot serialization, maybe you are right - I need to review how stubs work again. I think they will change a bit for the next iteration of this library for Vue 3, since they are pretty buggy, so now is a good chance to decide what they should and shouldn't do. I think we should make the more test friendly, so instead of |
Any update on this? |
No update on this, most of my time is on Vue 3 integration and vue-jest. I am also not sure how big a problem this really is - the point of snapshots really is to tell you if anything changed, so this isn't really blocking anyone as far as I can tell. Thinking about this more now, it seems like having the default prop isn't really a bad thing - if you changed that unintentionally, the snapshot would inform you (good thing, right?) Do you feel strongly about this @protium-dev? What do you think? Is there a specific point in the discussion about you would like to see some action on (a few things were discussed). |
I think the most painful aspect of this is when you add an optional prop to a component. That should be a backwards-compatible change (assuming its default value leads to no change in behaviour), but Worse, a fully If a newly-added optional prop or an existing optional prop's value is important in a given test on another component, that's probably more of an integration test, and Since others have argued in favour of the current behaviour, WDYT of making the default serialisation/stubbing logic of |
I have not looked into snapshot serializing much, but I wonder if it would make more sense for this to be customizable via an option in the snapshot serializer, as opposed to in VTU. |
Version
1.0.0-beta.31
Reproduction link
https://codesandbox.io/s/eloquent-mirzakhani-1im92?fontsize=14&hidenavigation=1&theme=dark
Steps to reproduce
See CodeSandbox. The HelloWorld component sets a default prop on id which the stub is reflecting (you can see the printed snapshot in the test even though it errors because it can't save it)
What is expected?
I think I would expect not too see the default prop "id" in the snapshot as it is part of the stubbed components logic - logic you would expect to not be executed because of the stubbing action
What is actually happening?
The default prop is set and visible in the snapshot
I'm generally interested on the design thoughts on this one and whether it constitutes a legitimate bug. For me I am seeing "id" props being set by vue-material MdInput components in a shallow mount. These ids have random characters in them which is causing my snapshots to be different each time. So in a shallow mount I wouldn't expect this interference from the component in the wrapper.
The text was updated successfully, but these errors were encountered: