createApp.spec.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { vi } from 'vitest'
  2. import { createApp, h } from '../src'
  3. describe('createApp for dom', () => {
  4. // #2926
  5. test('mount to SVG container', () => {
  6. const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
  7. createApp({
  8. render() {
  9. return h('g')
  10. }
  11. }).mount(root)
  12. expect(root.children.length).toBe(1)
  13. expect(root.children[0] instanceof SVGElement).toBe(true)
  14. })
  15. // #4398
  16. test('should not mutate original root component options object', () => {
  17. const originalObj = {
  18. data() {
  19. return {
  20. counter: 0
  21. }
  22. }
  23. }
  24. const handler = vi.fn(msg => {
  25. expect(msg).toMatch(`Component is missing template or render function`)
  26. })
  27. const Root = { ...originalObj }
  28. const app = createApp(Root)
  29. app.config.warnHandler = handler
  30. app.mount(document.createElement('div'))
  31. // ensure mount is based on a copy of Root object rather than Root object itself
  32. expect(app._component).not.toBe(Root)
  33. // ensure no mutation happened to Root object
  34. expect(originalObj).toMatchObject(Root)
  35. })
  36. })