]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: add test case edison/fix/12702 12705/head
authordaiwei <daiwei521@126.com>
Tue, 14 Jan 2025 01:24:31 +0000 (09:24 +0800)
committerdaiwei <daiwei521@126.com>
Tue, 14 Jan 2025 01:24:31 +0000 (09:24 +0800)
packages/runtime-core/__tests__/components/Teleport.spec.ts

index 79125cd04dfdccf918e27643e36d53e930e6586d..1cf83dd35d35f3b2da1dfeb29c25b3bc99005eec 100644 (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()