test: add test case

This commit is contained in:
daiwei 2025-01-14 09:24:31 +08:00
parent 6daa180de9
commit 1b12b404b0
1 changed files with 30 additions and 0 deletions

View File

@ -719,6 +719,36 @@ describe('renderer: teleport', () => {
expect(root.innerHTML).toBe('<!--v-if-->')
})
test('skip unmount children if teleport not disabled & target missing', async () => {
const root = document.createElement('div')
const childShow = ref(true)
const Comp = {
setup() {
return () => h(Teleport, { to: null }, [h('div', 'foo')])
},
}
const App = defineComponent({
setup() {
return () => {
return h(Fragment, { key: 0 }, [
childShow.value ? h(Comp) : createCommentVNode('v-if'),
])
}
},
})
domRender(h(App), root)
expect('Invalid Teleport target: null').toHaveBeenWarned()
expect('Invalid Teleport target on mount').toHaveBeenWarned()
expect(root.innerHTML).toBe('<!--teleport start--><!--teleport end-->')
childShow.value = false
await nextTick()
expect(root.innerHTML).toBe('<!--v-if-->')
})
test('accessing template refs inside teleport', async () => {
const target = nodeOps.createElement('div')
const tRef = ref()