Skip to content

Adding method to set data object  #563

@shortdiv

Description

@shortdiv

What problem does this feature solve?

Currently, setData only works with setting single data values, but it doesn't allow for setting objects. For example, given { text : { message: 'null' } }, I can't set the data with setData without mutating the entire object; i.e. setData({ text: { message: 'hello' } }).

This is problematic because I might want to append a k/v pair to an object while still preserving existing k/v pairs. While this functionality is available via "vanilla vue" through wrapper.vm.$set(obj, key, value), it feels like an inconsistency given that you can set data using setData otherwise.

What does the proposed API look like?

The proposed API adds a setDataObj method to vue-test-utils thereby allowing you to set data if updating an object rather than a value. It would be very similar to Vue.set or vm.$set but be more consistent with how data is currently set in tests.

setDataObj(obj, key, value)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions