|
|
@@ -1,7 +1,8 @@
|
|
|
-import { createApp, h } from '@vue/runtime-dom'
|
|
|
+import { createApp, h, nextTick, ref } from '@vue/runtime-dom'
|
|
|
import {
|
|
|
createComponent,
|
|
|
createDynamicComponent,
|
|
|
+ createFor,
|
|
|
createSlot,
|
|
|
defineVaporComponent,
|
|
|
setInsertionState,
|
|
|
@@ -374,6 +375,74 @@ describe('scopeId', () => {
|
|
|
`</div>`,
|
|
|
)
|
|
|
})
|
|
|
+
|
|
|
+ test('nested components in vFor with slots', async () => {
|
|
|
+ const Parent = defineVaporComponent({
|
|
|
+ setup() {
|
|
|
+ const n1 = template('<div>', true)() as any
|
|
|
+ setInsertionState(n1, null, 0, true)
|
|
|
+ createSlot('default', null)
|
|
|
+ return n1
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const Child = defineVaporComponent({
|
|
|
+ setup() {
|
|
|
+ const n1 = template('<div>', true)() as any
|
|
|
+ setInsertionState(n1, null, 0, true)
|
|
|
+ createSlot('default', null)
|
|
|
+ return n1
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const count = ref(0)
|
|
|
+ const { html } = define({
|
|
|
+ __scopeId: 'app',
|
|
|
+ setup() {
|
|
|
+ const n4 = createComponent(
|
|
|
+ Parent,
|
|
|
+ null,
|
|
|
+ {
|
|
|
+ default: withVaporCtx(() => {
|
|
|
+ const n0 = createFor(
|
|
|
+ () => count.value,
|
|
|
+ _for_item0 => {
|
|
|
+ const n3 = createComponent(
|
|
|
+ Child,
|
|
|
+ { class: () => 'test' },
|
|
|
+ {
|
|
|
+ default: () => {
|
|
|
+ const n2 = template('<div> red ')()
|
|
|
+ return n2
|
|
|
+ },
|
|
|
+ },
|
|
|
+ )
|
|
|
+ return n3
|
|
|
+ },
|
|
|
+ item => item,
|
|
|
+ 2,
|
|
|
+ )
|
|
|
+ return n0
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ true,
|
|
|
+ )
|
|
|
+ return n4
|
|
|
+ },
|
|
|
+ }).render()
|
|
|
+
|
|
|
+ expect(html()).toBe(`<div app=""><!--for--><!--slot--></div>`)
|
|
|
+
|
|
|
+ count.value++
|
|
|
+ await nextTick()
|
|
|
+ expect(html()).toBe(
|
|
|
+ `<div app="">` +
|
|
|
+ `<div class="test" app="">` + // should have app scopeId
|
|
|
+ `<div> red </div><!--slot-->` +
|
|
|
+ `</div><!--for-->` +
|
|
|
+ `<!--slot--></div>`,
|
|
|
+ )
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('vdom interop', () => {
|