2019-09-20 12:56:02 +08:00
|
|
|
import { createApp } from '../src'
|
2019-10-16 05:50:38 +08:00
|
|
|
import { mockWarn } from '@vue/runtime-test'
|
2019-09-20 12:56:02 +08:00
|
|
|
|
2019-10-16 05:50:38 +08:00
|
|
|
describe('compiler + runtime integration', () => {
|
|
|
|
mockWarn()
|
|
|
|
|
|
|
|
it('should support on-the-fly template compilation', () => {
|
|
|
|
const container = document.createElement('div')
|
|
|
|
const App = {
|
|
|
|
template: `{{ count }}`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
count: 0
|
|
|
|
}
|
2019-09-20 12:56:02 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-16 05:50:38 +08:00
|
|
|
createApp().mount(App, container)
|
|
|
|
expect(container.innerHTML).toBe(`0`)
|
|
|
|
})
|
2019-10-12 03:09:37 +08:00
|
|
|
|
2019-10-16 05:50:38 +08:00
|
|
|
it('should warn template compilation errors with codeframe', () => {
|
|
|
|
const container = document.createElement('div')
|
|
|
|
const App = {
|
|
|
|
template: `<div v-if>`
|
2019-10-12 03:09:37 +08:00
|
|
|
}
|
2019-10-16 05:50:38 +08:00
|
|
|
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()
|
|
|
|
})
|
2019-10-16 05:30:47 +08:00
|
|
|
|
2019-10-16 05:50:38 +08:00
|
|
|
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>')
|
|
|
|
})
|
2019-10-16 05:30:47 +08:00
|
|
|
})
|