Skip to content

Commit 59a26a0

Browse files
committed
Updated set data method
1 parent 498c2fd commit 59a26a0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/test-utils/src/wrapper.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,13 @@ export default class Wrapper implements BaseWrapper {
421421

422422
Object.keys(data).forEach((key) => {
423423
// $FlowIgnore : Problem with possibly null this.vm
424-
this.vm.$set(this.vm, [key], data[key])
424+
if(typeof data[key] === typeof {} && data[key] !== null) {
425+
Object.keys(data[key]).forEach((key2) => {
426+
this.vm.$set(this.vm[key], key2, data[key][key2])
427+
})
428+
} else {
429+
this.vm.$set(this.vm, [key], data[key])
430+
}
425431
})
426432
}
427433

test/specs/wrapper/setData.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,21 @@ describeWithShallowAndMount('setData', (mountingMethod) => {
132132
wrapper.setData({ message: null })
133133
expect(wrapper.text()).to.equal('There is no message yet')
134134
})
135+
it('should update a data object', () => {
136+
const TestComponent = {
137+
data: () => ({
138+
message: {
139+
text: 'hello'
140+
}
141+
})
142+
}
143+
const wrapper = mountingMethod(TestComponent)
144+
wrapper.setData({
145+
message: {
146+
read: true
147+
}
148+
})
149+
expect(wrapper.vm.message.text).to.equal('hello')
150+
expect(wrapper.vm.message.read).to.equal(true)
151+
})
135152
})

0 commit comments

Comments
 (0)