Skip to content

Bug: setData() incorrectly sets object prototype methods as keys #2257

@MetRonnie

Description

@MetRonnie

Describe the bug

Using setData() with an object is causing Object prototype methods to be set as keys on the object.

To Reproduce

Stackblitz isn't loading for me. But here is hopefully a clear example:

const wrapper = mountFunction()
expect(wrapper.vm.filters).toEqual({
  'workflow state': [],
  'task state': [],
}) // ✔
expect(Object.keys(wrapper.vm.filters)).toEqual([
  'workflow state',
  'task state',
]) // ✔

await wrapper.setData({
  filters: {
    'workflow state': [],
    'task state': [],
  }
})
expect(Object.keys(wrapper.vm.filters)).toEqual([
  'workflow state',
  'task state',
]) // ✖
- Expected
+ Received

  Array [
    "workflow state",
    "task state",
+   "constructor",
+   "__defineGetter__",
+   "__defineSetter__",
+   "hasOwnProperty",
+   "__lookupGetter__",
+   "__lookupSetter__",
+   "isPrototypeOf",
+   "propertyIsEnumerable",
+   "toString",
+   "valueOf",
+   "toLocaleString",

Expected behavior

Object prototype methods should not be set as keys on objects.

Related information:

    "vue": "3.3.4",
    "@vue/test-utils": "2.4.2",
    "vitest": "0.34.6"

Additional context

I think this was introduced by #2166

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions