Skip to content

Commit

Permalink
fix: do not deep merge array data (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
lchanmann authored and eddyerburgh committed May 14, 2018
1 parent 3e673ae commit 934745b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ export default class Wrapper implements BaseWrapper {
}

Object.keys(data).forEach((key) => {
if (typeof data[key] === 'object' && data[key] !== null) {
if (typeof data[key] === 'object' && data[key] !== null &&
!Array.isArray(data[key])) {
// $FlowIgnore : Problem with possibly null this.vm
const newObj = merge(this.vm[key], data[key])
// $FlowIgnore : Problem with possibly null this.vm
Expand Down
13 changes: 13 additions & 0 deletions test/specs/wrapper/setData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,17 @@ describeWithShallowAndMount('setData', (mountingMethod) => {
expect(wrapper.vm.anObject.propA.prop1).to.equal('a')
expect(wrapper.vm.anObject.propA.prop2).to.equal('b')
})

it('sets array data properly', () => {
const TestComponent = {
data: () => ({
items: [1, 2]
})
}
const wrapper = mountingMethod(TestComponent)
wrapper.setData({
items: [3]
})
expect(wrapper.vm.items).to.deep.equal([3])
})
})

0 comments on commit 934745b

Please sign in to comment.