| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import { createApp } from '../src'
- import { mockWarn } from '@vue/runtime-test'
- describe('compiler + runtime integration', () => {
- mockWarn()
- it('should support runtime template compilation', () => {
- const container = document.createElement('div')
- const App = {
- template: `{{ count }}`,
- data() {
- return {
- count: 0
- }
- }
- }
- createApp().mount(App, container)
- expect(container.innerHTML).toBe(`0`)
- })
- it('should support runtime template via CSS ID selector', () => {
- const container = document.createElement('div')
- const template = document.createElement('div')
- template.id = 'template'
- template.innerHTML = '{{ count }}'
- document.body.appendChild(template)
- const App = {
- template: `#template`,
- data() {
- return {
- count: 0
- }
- }
- }
- createApp().mount(App, container)
- expect(container.innerHTML).toBe(`0`)
- })
- it('should support runtime template via direct DOM node', () => {
- const container = document.createElement('div')
- const template = document.createElement('div')
- template.id = 'template'
- template.innerHTML = '{{ count }}'
- const App = {
- template,
- data() {
- return {
- count: 0
- }
- }
- }
- createApp().mount(App, container)
- expect(container.innerHTML).toBe(`0`)
- })
- it('should warn template compilation errors with codeframe', () => {
- const container = document.createElement('div')
- const App = {
- template: `<div v-if>`
- }
- createApp().mount(App, container)
- expect(
- `Template compilation error: End tag was not found`
- ).toHaveBeenWarned()
- expect(`v-if/v-else-if is missing expression`).toHaveBeenWarned()
- expect(
- `
- 1 | <div v-if>
- | ^^^^`.trim()
- ).toHaveBeenWarned()
- })
- it('should support custom element', () => {
- const app = createApp()
- const container = document.createElement('div')
- const App = {
- template: '<custom></custom>'
- }
- app.config.isCustomElement = tag => tag === 'custom'
- app.mount(App, container)
- expect(container.innerHTML).toBe('<custom></custom>')
- })
- it('should support using element innerHTML as template', () => {
- const app = createApp()
- const container = document.createElement('div')
- container.innerHTML = '{{msg}}'
- const App = {
- data: {
- msg: 'hello'
- }
- }
- app.mount(App, container)
- expect(container.innerHTML).toBe('hello')
- })
- })
|