Sfoglia il codice sorgente

test(runtime-vapor): cover forwarded slot fragments after fallback addition

daiwei 2 mesi fa
parent
commit
8106ec370d
1 ha cambiato i file con 43 aggiunte e 0 eliminazioni
  1. 43 0
      packages/runtime-vapor/__tests__/componentSlots.spec.ts

+ 43 - 0
packages/runtime-vapor/__tests__/componentSlots.spec.ts

@@ -2482,6 +2482,49 @@ describe('component: slots', () => {
         expect(mountSpy).toHaveBeenCalledTimes(1)
       })
 
+      test('vdom fallback added over forwarded vapor slot fragments should activate when slot content later becomes invalid', async () => {
+        const useFallback = ref(false)
+        const foo = ref('content')
+        const showContent = ref(true)
+
+        const VdomSlotWithOptionalFallback = {
+          render(this: any) {
+            return renderSlot(
+              this.$slots,
+              'foo',
+              {},
+              useFallback.value ? () => [h('div', 'fallback')] : undefined,
+            )
+          },
+        }
+
+        const VaporForwardedSlot = defineVaporComponent({
+          setup() {
+            return createComponent(
+              VdomSlotWithOptionalFallback,
+              null,
+              {
+                foo: withVaporCtx(() => createSlot('foo', null)),
+              },
+              true,
+            )
+          },
+        })
+
+        const App = createTestApp(VaporForwardedSlot, foo, showContent)
+        const root = document.createElement('div')
+        createApp(App).use(vaporInteropPlugin).mount(root)
+        expect(root.innerHTML).toBe('<span>content</span>')
+
+        useFallback.value = true
+        await nextTick()
+        expect(root.innerHTML).toBe('<span>content</span>')
+
+        showContent.value = false
+        await nextTick()
+        expect(root.innerHTML).toBe('<div>fallback</div>')
+      })
+
       test('vdom fallback added later should propagate to nested slot boundaries inside still-valid content', async () => {
         const useFallback = ref(false)
         const showInner = ref(true)