fix(compat): fix deep data merge with extended constructor

fix #3852
This commit is contained in:
Evan You 2021-05-31 16:48:18 -04:00
parent ecd97ee6e4
commit c7efb967ca
2 changed files with 27 additions and 3 deletions

View File

@ -19,6 +19,7 @@ export function deepMergeData(
to[key] = fromVal
}
}
return to
}
export function mergeDataOption(to: any, from: any) {

View File

@ -47,12 +47,15 @@ test('data deep merge', () => {
data: () => ({
foo: {
bar: 1
}
},
selfData: 3
}),
template: `{{ foo }}`
template: `{{ { selfData, foo } }}`
}).$mount()
expect(vm.$el.textContent).toBe(JSON.stringify({ baz: 2, bar: 1 }, null, 2))
expect(vm.$el.textContent).toBe(
JSON.stringify({ selfData: 3, foo: { baz: 2, bar: 1 } }, null, 2)
)
expect(
(deprecationData[DeprecationTypes.OPTIONS_DATA_MERGE].message as Function)(
'foo'
@ -60,6 +63,26 @@ test('data deep merge', () => {
).toHaveBeenWarned()
})
// #3852
test('data deep merge w/ extended constructor', () => {
const App = Vue.extend({
template: `<pre>{{ { mixinData, selfData } }}</pre>`,
mixins: [{ data: () => ({ mixinData: 'mixinData' }) }],
data: () => ({ selfData: 'selfData' })
})
const vm = new App().$mount()
expect(vm.$el.textContent).toBe(
JSON.stringify(
{
mixinData: 'mixinData',
selfData: 'selfData'
},
null,
2
)
)
})
test('beforeDestroy/destroyed', async () => {
const beforeDestroy = jest.fn()
const destroyed = jest.fn()