Vue-test-utils: Can wrapper.setData be used to set data which is a nested object without setting entire object?

Created on 13 Mar 2019  ·  2Comments  ·  Source: vuejs/vue-test-utils

What problem does this feature solve?

As title.

P.S. What's the diff between setting a data directly (like wrapper.vm.$data.foo = 'foo') versus using wrapper.setData (like wrapper.setData({foo: 'foo'}) ? Is it just is a shortcut?

What does the proposed API look like?

If it doesn't, I suggest we can provide a new function that accept a object path selector instead of a simple data name, for instance:

// setting wrapper.vm.$data.time.date to 'now'
wrapper.setData({ 'time.date': 'now' })
feature request

Most helpful comment

@eddyerburgh If it isn't on the pipeline or anyone else isn't working on this, I'm interested in taking a look at this. This is a feature I wanted too 👍 Let me know.

All 2 comments

@eddyerburgh If it isn't on the pipeline or anyone else isn't working on this, I'm interested in taking a look at this. This is a feature I wanted too 👍 Let me know.

Hey! 👋

setData() calls vm.$set() for each piece of state and it only modifies the desired key, not the whole object.

Was this page helpful?
0 / 5 - 0 ratings