|
|
@@ -527,6 +527,46 @@ describe('component: slots', () => {
|
|
|
expect(host.innerHTML).toBe('<div><h1></h1><!--slot--></div>')
|
|
|
})
|
|
|
|
|
|
+ test('slots proxy ownKeys trap correctly reflects dynamic slot presence', async () => {
|
|
|
+ const val = ref('header')
|
|
|
+ const toggle = ref(false)
|
|
|
+
|
|
|
+ let instance: any
|
|
|
+ const Comp = defineVaporComponent(() => {
|
|
|
+ instance = currentInstance
|
|
|
+ const n0 = template('<div></div>')()
|
|
|
+ prepend(n0 as any as ParentNode, createSlot('header', null))
|
|
|
+ return n0
|
|
|
+ })
|
|
|
+
|
|
|
+ define(() => {
|
|
|
+ // dynamic slot
|
|
|
+ return createComponent(Comp, null, {
|
|
|
+ $: [
|
|
|
+ () =>
|
|
|
+ (toggle.value
|
|
|
+ ? {
|
|
|
+ name: val.value,
|
|
|
+ fn: () => {
|
|
|
+ return template('<h1></h1>')()
|
|
|
+ },
|
|
|
+ }
|
|
|
+ : void 0) as DynamicSlot,
|
|
|
+ ],
|
|
|
+ })
|
|
|
+ }).render()
|
|
|
+
|
|
|
+ expect(Reflect.ownKeys(instance.slots)).not.toContain('header')
|
|
|
+
|
|
|
+ toggle.value = true
|
|
|
+ await nextTick()
|
|
|
+ expect(Reflect.ownKeys(instance.slots)).toContain('header')
|
|
|
+
|
|
|
+ toggle.value = false
|
|
|
+ await nextTick()
|
|
|
+ expect(Reflect.ownKeys(instance.slots)).not.toContain('header')
|
|
|
+ })
|
|
|
+
|
|
|
test('render fallback when slot content is not valid', async () => {
|
|
|
const Child = {
|
|
|
setup() {
|