2
0

createApp.spec.ts 1.1 KB

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