index.spec.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { createApp } from '../src'
  2. import { mockWarn } from '@vue/runtime-test'
  3. describe('compiler + runtime integration', () => {
  4. mockWarn()
  5. it('should support on-the-fly template compilation', () => {
  6. const container = document.createElement('div')
  7. const App = {
  8. template: `{{ count }}`,
  9. data() {
  10. return {
  11. count: 0
  12. }
  13. }
  14. }
  15. createApp().mount(App, container)
  16. expect(container.innerHTML).toBe(`0`)
  17. })
  18. it('should warn template compilation errors with codeframe', () => {
  19. const container = document.createElement('div')
  20. const App = {
  21. template: `<div v-if>`
  22. }
  23. createApp().mount(App, container)
  24. expect(
  25. `Template compilation error: End tag was not found`
  26. ).toHaveBeenWarned()
  27. expect(`v-if/v-else-if is missing expression`).toHaveBeenWarned()
  28. expect(
  29. `
  30. 1 | <div v-if>
  31. | ^^^^`.trim()
  32. ).toHaveBeenWarned()
  33. })
  34. it('should support custom element', () => {
  35. const app = createApp()
  36. const container = document.createElement('div')
  37. const App = {
  38. template: '<custom></custom>'
  39. }
  40. app.config.isCustomElement = tag => tag === 'custom'
  41. app.mount(App, container)
  42. expect(container.innerHTML).toBe('<custom></custom>')
  43. })
  44. it('should support using element innerHTML as template', () => {
  45. const app = createApp()
  46. const container = document.createElement('div')
  47. container.innerHTML = '{{msg}}'
  48. const App = {
  49. data: {
  50. msg: 'hello'
  51. }
  52. }
  53. app.mount(App, container)
  54. expect(container.innerHTML).toBe('hello')
  55. })
  56. })