Skip to content

Bug: setData with classes/Object prototypes does not work correctly #1851

@jacksongross

Description

@jacksongross

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 with wrapper.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.0
  • Vue version: 3.2.37
  • node version: 16.15.0
  • npm (or yarn) version: 8.10.0

I can see a fix was applied specifically for Date objects but feel the real problem isn't solved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions