-
Notifications
You must be signed in to change notification settings - Fork 257
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
Bug: setData with classes/Object prototypes does not work correctly #1851
Comments
Thanks for the repo! This indeed looks like an issue.
It looks like the answer was updated with a reference to https://jhildenbiddle.github.io/mergician/#/ I wonder if this lib handles this use-case? Maybe we could use it, or at least improve Would you like to try and open a PR to solve it? Any help would be gladly appreciated! |
Yeah I might take a stab at this when I have some extra time in the next week or so. |
Just to check you said
We are on 2.2.2 now - there has been many releases since 2.0.0, might be worth updating? That said, I don't think we've changed |
It makes no difference -- as you said, the |
Right, fair enough. We should update |
Currently, when calling setData on a wrapper it will not retain methods on any constructed objects passed in. These methods reside in the prototype which the current logic does not persist across. These changes will ensure that any prototype properties/methods are copied over to the proxied data object. fixes #1851
Describe the bug
When testing a component that calls
setData
with a non-primitive class/object, the object gets set into the component VM without the prototype properties which breaks what should be a straightforward test. If you set the data property on the VM property directly withwrapper.vm.foo = bar
it works as expected.To Reproduce
Made a very basic example that illustrates the bug relating to the mergeDeep behaviour when calling setData
https://stackblitz.com/edit/vue3-script-setup-with-vite-prcxxz?file=src%2Fcomponents%2FHelloWorld.spec.ts,src%2Fcomponents%2FMyObject.js,src%2Fcomponents%2FHelloWorld.vue,src%2FApp.vue
Expected behavior
I expect that calling
setData
will simply set the property on the component's VM without modification.Related information:
@vue/test-utils
version: 2.0.0Vue
version: 3.2.37node
version: 16.15.0npm
(oryarn
) version: 8.10.0I can see a fix was applied specifically for Date objects but feel the real problem isn't solved.
The text was updated successfully, but these errors were encountered: