', 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('
red ')()
return n2
},
},
)
return n3
},
item => item,
2,
)
return n0
}),
},
true,
)
return n4
},
}).render()
expect(html()).toBe(`
`)
count.value++
await nextTick()
expect(html()).toBe(
`
` +
`
` + // should have app scopeId
`
red
` +
`
` +
`
`,
)
})
})
describe('vdom interop', () => {
test('vdom parent > vapor child', () => {
const VaporChild = defineVaporComponent({
__scopeId: 'vapor-child',
setup() {
return template('
', true)()
},
})
const VdomParent = {
__scopeId: 'vdom-parent',
setup() {
return () => h(VaporChild as any)
},
}
const App = {
setup() {
return () => h(VdomParent)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vdom parent > vapor child > vdom child', () => {
const VdomChild = {
__scopeId: 'vdom-child',
setup() {
return () => h('button')
},
}
const VaporChild = defineVaporComponent({
__scopeId: 'vapor-child',
setup() {
return createComponent(VdomChild as any, null, null, true)
},
})
const VdomParent = {
__scopeId: 'vdom-parent',
setup() {
return () => h(VaporChild as any)
},
}
const App = {
setup() {
return () => h(VdomParent)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vdom parent > vapor child > vapor child > vdom child', () => {
const VdomChild = {
__scopeId: 'vdom-child',
setup() {
return () => h('button')
},
}
const NestedVaporChild = defineVaporComponent({
__scopeId: 'nested-vapor-child',
setup() {
return createComponent(VdomChild as any, null, null, true)
},
})
const VaporChild = defineVaporComponent({
__scopeId: 'vapor-child',
setup() {
return createComponent(NestedVaporChild as any, null, null, true)
},
})
const VdomParent = {
__scopeId: 'vdom-parent',
setup() {
return () => h(VaporChild as any)
},
}
const App = {
setup() {
return () => h(VdomParent)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vdom parent > vapor dynamic child', () => {
const VaporChild = defineVaporComponent({
__scopeId: 'vapor-child',
setup() {
return createDynamicComponent(() => 'button', null, null, true)
},
})
const VdomParent = {
__scopeId: 'vdom-parent',
setup() {
return () => h(VaporChild as any)
},
}
const App = {
setup() {
return () => h(VdomParent)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vapor parent > vdom child', () => {
const VdomChild = {
__scopeId: 'vdom-child',
setup() {
return () => h('button')
},
}
const VaporParent = defineVaporComponent({
__scopeId: 'vapor-parent',
setup() {
return createComponent(VdomChild as any, null, null, true)
},
})
const App = {
setup() {
return () => h(VaporParent as any)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vapor parent > vdom child > vapor child', () => {
const VaporChild = defineVaporComponent({
__scopeId: 'vapor-child',
setup() {
return template('
', true)()
},
})
const VdomChild = {
__scopeId: 'vdom-child',
setup() {
return () => h(VaporChild as any)
},
}
const VaporParent = defineVaporComponent({
__scopeId: 'vapor-parent',
setup() {
return createComponent(VdomChild as any, null, null, true)
},
})
const App = {
setup() {
return () => h(VaporParent as any)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vapor parent > vdom child > vdom child > vapor child', () => {
const VaporChild = defineVaporComponent({
__scopeId: 'vapor-child',
setup() {
return template('
', true)()
},
})
const VdomChild = {
__scopeId: 'vdom-child',
setup() {
return () => h(VaporChild as any)
},
}
const VdomParent = {
__scopeId: 'vdom-parent',
setup() {
return () => h(VdomChild as any)
},
}
const VaporParent = defineVaporComponent({
__scopeId: 'vapor-parent',
setup() {
return createComponent(VdomParent as any, null, null, true)
},
})
const App = {
setup() {
return () => h(VaporParent as any)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
test('vapor parent > vapor slot > vdom child', () => {
const VaporSlot = defineVaporComponent({
__scopeId: 'vapor-slot',
setup() {
const n1 = template('
', true)() as any
setInsertionState(n1)
createSlot('default', null)
return n1
},
})
const VdomChild = {
__scopeId: 'vdom-child',
setup() {
return () => h('span')
},
}
const VaporParent = defineVaporComponent({
__scopeId: 'vapor-parent',
setup() {
const n2 = createComponent(
VaporSlot,
null,
{
default: withVaporCtx(() => {
const n0 = template('
')()
const n1 = createComponent(VdomChild)
return [n0, n1]
}),
},
true,
)
return n2
},
})
const App = {
setup() {
return () => h(VaporParent as any)
},
}
const root = document.createElement('div')
createApp(App).use(vaporInteropPlugin).mount(root)
expect(root.innerHTML).toBe(
`
`,
)
})
})