Skip to content

Commit 934745b

Browse files
lchanmanneddyerburgh
authored andcommitted
fix: do not deep merge array data (#604)
1 parent 3e673ae commit 934745b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: packages/test-utils/src/wrapper.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ export default class Wrapper implements BaseWrapper {
421421
}
422422

423423
Object.keys(data).forEach((key) => {
424-
if (typeof data[key] === 'object' && data[key] !== null) {
424+
if (typeof data[key] === 'object' && data[key] !== null &&
425+
!Array.isArray(data[key])) {
425426
// $FlowIgnore : Problem with possibly null this.vm
426427
const newObj = merge(this.vm[key], data[key])
427428
// $FlowIgnore : Problem with possibly null this.vm

Diff for: test/specs/wrapper/setData.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,17 @@ describeWithShallowAndMount('setData', (mountingMethod) => {
178178
expect(wrapper.vm.anObject.propA.prop1).to.equal('a')
179179
expect(wrapper.vm.anObject.propA.prop2).to.equal('b')
180180
})
181+
182+
it('sets array data properly', () => {
183+
const TestComponent = {
184+
data: () => ({
185+
items: [1, 2]
186+
})
187+
}
188+
const wrapper = mountingMethod(TestComponent)
189+
wrapper.setData({
190+
items: [3]
191+
})
192+
expect(wrapper.vm.items).to.deep.equal([3])
193+
})
181194
})

0 commit comments

Comments
 (0)