| ^`.trim()
).toHaveBeenWarned()
expect(`v-if/v-else-if is missing expression`).toHaveBeenWarned()
expect(
`
1 |
| ^^^^`.trim()
).toHaveBeenWarned()
})
it('should support custom element', () => {
const app = createApp({
template: '
'
})
const container = document.createElement('div')
app.config.isCustomElement = tag => tag === 'custom'
app.mount(container)
expect(container.innerHTML).toBe('
')
})
it('should support using element innerHTML as template', () => {
const app = createApp({
data: () => ({
msg: 'hello'
})
})
const container = document.createElement('div')
container.innerHTML = '{{msg}}'
app.mount(container)
expect(container.innerHTML).toBe('hello')
})
it('should support selector of rootContainer', () => {
const container = document.createElement('div')
const origin = document.querySelector
document.querySelector = jest.fn().mockReturnValue(container)
const App = {
template: `{{ count }}`,
data() {
return {
count: 0
}
}
}
createApp(App).mount('#app')
expect(container.innerHTML).toBe(`0`)
document.querySelector = origin
})
it('should warn when template is not available', () => {
const app = createApp({
template: {}
})
const container = document.createElement('div')
app.mount(container)
expect('[Vue warn]: invalid template option:').toHaveBeenWarned()
})
it('should warn when template is is not found', () => {
const app = createApp({
template: '#not-exist-id'
})
const container = document.createElement('div')
app.mount(container)
expect(
'[Vue warn]: Template element not found or is empty: #not-exist-id'
).toHaveBeenWarned()
})
it('should warn when container is not found', () => {
const origin = document.querySelector
document.querySelector = jest.fn().mockReturnValue(null)
const App = {
template: `{{ count }}`,
data() {
return {
count: 0
}
}
}
createApp(App).mount('#not-exist-id')
expect(
'[Vue warn]: Failed to mount app: mount target selector returned null.'
).toHaveBeenWarned()
document.querySelector = origin
})
// #1813
it('should not report an error when "0" as patchFlag value', async () => {
const container = document.createElement('div')
const target = document.createElement('div')
const count = ref(0)
const origin = document.querySelector
document.querySelector = jest.fn().mockReturnValue(target)
const App = {
template: `
`,
data() {
return {
count
}
}
}
createApp(App).mount(container)
expect(container.innerHTML).toBe(``)
expect(target.innerHTML).toBe(`
`)
count.value++
await nextTick()
expect(container.innerHTML).toBe(``)
expect(target.innerHTML).toBe(`
`)
count.value++
await nextTick()
expect(container.innerHTML).toBe(``)
expect(target.innerHTML).toBe(``)
document.querySelector = origin
})
test('v-if + v-once', async () => {
const ok = ref(true)
const App = {
setup() {
return { ok }
},
template: `
`
}
const container = document.createElement('div')
createApp(App).mount(container)
expect(container.innerHTML).toBe(`
`)
ok.value = false
await nextTick()
expect(container.innerHTML).toBe(`
`)
})
test('v-for + v-once', async () => {
const list = reactive([1])
const App = {
setup() {
return { list }
},
template: `
`
}
const container = document.createElement('div')
createApp(App).mount(container)
expect(container.innerHTML).toBe(`
`)
list.push(2)
await nextTick()
expect(container.innerHTML).toBe(`
`)
})
})