2021-03-02 00:51:32 +08:00
|
|
|
import { createApp, h } from '../src'
|
|
|
|
|
|
|
|
describe('createApp for dom', () => {
|
|
|
|
// #2926
|
|
|
|
test('mount to SVG container', () => {
|
|
|
|
const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
|
|
|
createApp({
|
|
|
|
render() {
|
|
|
|
return h('g')
|
|
|
|
}
|
|
|
|
}).mount(root)
|
|
|
|
expect(root.children.length).toBe(1)
|
|
|
|
expect(root.children[0] instanceof SVGElement).toBe(true)
|
|
|
|
})
|
2022-04-12 15:14:23 +08:00
|
|
|
|
|
|
|
// #4398
|
|
|
|
test('should not mutate original root component options object', () => {
|
2022-05-13 07:10:00 +08:00
|
|
|
const originalObj = {
|
2022-04-12 15:14:23 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
counter: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const handler = jest.fn(msg => {
|
|
|
|
expect(msg).toMatch(`Component is missing template or render function`)
|
|
|
|
})
|
|
|
|
|
2022-05-13 07:10:00 +08:00
|
|
|
const Root = { ...originalObj }
|
|
|
|
|
2022-04-12 15:14:23 +08:00
|
|
|
const app = createApp(Root)
|
|
|
|
app.config.warnHandler = handler
|
2022-05-13 07:10:00 +08:00
|
|
|
app.mount(document.createElement('div'))
|
|
|
|
|
|
|
|
// ensure mount is based on a copy of Root object rather than Root object itself
|
2022-04-12 15:14:23 +08:00
|
|
|
expect(app._component).not.toBe(Root)
|
2022-05-13 07:10:00 +08:00
|
|
|
|
2022-04-12 15:14:23 +08:00
|
|
|
// ensure no mutation happened to Root object
|
|
|
|
expect(originalObj).toMatchObject(Root)
|
|
|
|
})
|
2021-03-02 00:51:32 +08:00
|
|
|
})
|