fix(runtime-core): Avoid mutating original options object in createApp (#4840)

fix #4398
This commit is contained in:
Yuchao
2022-04-12 17:14:23 +10:00
committed by GitHub
parent 4311dddfa7
commit d121a9bc7e
3 changed files with 36 additions and 2 deletions

View File

@@ -12,4 +12,33 @@ describe('createApp for dom', () => {
expect(root.children.length).toBe(1)
expect(root.children[0] instanceof SVGElement).toBe(true)
})
// #4398
test('should not mutate original root component options object', () => {
const originalObj = {
data() {
return {
counter: 0
}
}
}
const handler = jest.fn(msg => {
expect(msg).toMatch(`Component is missing template or render function`)
})
const Root = { ...originalObj}
const app = createApp(Root)
app.config.warnHandler = handler
app.mount(document.createElement('div'))
// ensure mount is based on a copy of Root object rather than Root object itself
expect(app._component).not.toBe(Root)
// ensure no mutation happened to Root object
expect(originalObj).toMatchObject(Root)
})
})