-
Notifications
You must be signed in to change notification settings - Fork 240
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
feat: Hide props with default values within snapshot #1174
Conversation
Will this only impact |
It only impact stubbed components so |
…alue # Conflicts: # src/stubs.ts # tests/mountingOptions/global.stubs.spec.ts
I have added a util function |
I'd like some more feedback on this one, maybe @xanf or @cexbrayat or @afontcu ? My concern is PR adds a lot of complexity that I foresee as difficult to maintain and also will make it very hard to make changes without breaking snapshots. I'm thinking that VTU should not even be concerned with snapshots; this is a Jest only feature, which can be heavily customized with their snapshot serializer API. Furthermore, different people have different opinions on snapshots, and I don't think we should be enforcing any opinions on them. Knowing the default prop value is likely important for some people. Finally, this fix is specific to snapshots with shallowMount, a type of test which is going to be brittle and break at the slightest change to any implementation detail (good tests should be resilient to implementation details changing). How useful and beneficial is providing a highly opinionated snapshot, a feature where the desired behavior is different for each dev and testing framework? I feel like this is going to cause a lot of overhead in the future and we may unintentionally break snapshots in minor versions. I'd like to get some more feedback before we merge this. Thanks for the work so far! |
I understand your concerns. Another proposal could be to override the default stub generation by setting a function in the global mounting options. So something like: const wrapper = shallowMount(MyComponent, {
global: {
createStubs: ({ name, component }) => {
// Implement own logic to create a stub
return defineComponent({
name,
render: () => // Custom render logic
})
}
}
}) This will allow the user the customize the default stub generation when using |
I also tend to think it adds too much complexity for the benefits... |
Hi! First of all, thank you for your work on this, I actually learned a couple of things reading your code 🙌 That being said – I agree on the overall feeling of too much complexity – and also, a bit of opinionated. Assuming that component snapshot testing is useful, why wouldn't I get the default values of props? Or why wouldn't I want to break if prop order changes? With that, I believe this PR should not be merged, as the behavior of snapshot testing is not something Vue Test Utils should control extensively. Again, thanks! |
If you want to make a snapshot serializer that implements this same behavior and need VTU to expose things, we could do that. |
This PR will avoid props with their default values within snapshot (Fixes #945).
Will now be stubbed to
<my-component-stub />
and no longer to<my-component-stub some-props="default-value" />
.This may lead to invalid snapshots and could be a breaking change?
I currently use
JSON.stringify
for object comparison but I want to replace it.https://github.com/freakzlike/vue-test-utils-next/blob/efca188cf62bea1f0e4ed07c9cd4766016c1c71c/src/stubs.ts#L115-L116
Is there already any existing util for this? (I haved found one). If not I will create one.