| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939 |
- // NOTE: This test is implemented based on the case of `runtime-core/__test__/componentSlots.spec.ts`.
- import {
- child,
- createComponent,
- createFor,
- createForSlots,
- createIf,
- createSlot,
- createVaporApp,
- defineVaporComponent,
- insert,
- prepend,
- renderEffect,
- setInsertionState,
- template,
- txt,
- vaporInteropPlugin,
- withVaporCtx,
- } from '../src'
- import {
- type Ref,
- createApp,
- createSlots,
- currentInstance,
- h,
- nextTick,
- ref,
- renderSlot,
- toDisplayString,
- } from '@vue/runtime-dom'
- import { makeRender } from './_utils'
- import type { DynamicSlot } from '../src/componentSlots'
- import { setElementText, setText } from '../src/dom/prop'
- const define = makeRender<any>()
- function renderWithSlots(slots: any): any {
- let instance: any
- const Comp = defineVaporComponent({
- setup() {
- const t0 = template('<div></div>')
- const n0 = t0()
- instance = currentInstance
- return n0
- },
- })
- const { render } = define({
- render() {
- return createComponent(Comp, {}, slots)
- },
- })
- render()
- return instance
- }
- describe('component: slots', () => {
- test('initSlots: instance.slots should be set correctly', () => {
- const { slots } = renderWithSlots({
- default: () => template('<span></span>')(),
- })
- expect(slots.default()).toMatchObject(document.createElement('span'))
- })
- test('updateSlots: instance.slots should be updated correctly', async () => {
- const flag1 = ref(true)
- let instance: any
- const Child = () => {
- instance = currentInstance
- return template('child')()
- }
- const { render } = define({
- render() {
- return createComponent(
- Child,
- {},
- {
- $: [
- () =>
- flag1.value
- ? { name: 'one', fn: () => template('<span></span>')() }
- : { name: 'two', fn: () => template('<div></div>')() },
- ],
- },
- )
- },
- })
- render()
- expect(instance.slots).toHaveProperty('one')
- expect(instance.slots).not.toHaveProperty('two')
- flag1.value = false
- await nextTick()
- expect(instance.slots).not.toHaveProperty('one')
- expect(instance.slots).toHaveProperty('two')
- })
- test('should work with createFlorSlots', async () => {
- const loop = ref([1, 2, 3])
- let instance: any
- const Child = () => {
- instance = currentInstance
- return template('child')()
- }
- const { render } = define({
- setup() {
- return createComponent(Child, null, {
- $: [
- () =>
- createForSlots(loop.value, (item, i) => ({
- name: item,
- fn: () => template(item + i)(),
- })),
- ],
- })
- },
- })
- render()
- expect(instance.slots).toHaveProperty('1')
- expect(instance.slots).toHaveProperty('2')
- expect(instance.slots).toHaveProperty('3')
- loop.value.push(4)
- await nextTick()
- expect(instance.slots).toHaveProperty('4')
- loop.value.shift()
- await nextTick()
- expect(instance.slots).not.toHaveProperty('1')
- })
- // passes but no warning for slot invocation in vapor currently
- test.todo('should not warn when mounting another app in setup', () => {
- const Comp = defineVaporComponent({
- setup(_, { slots }) {
- return slots.default!()
- },
- })
- const mountComp = () => {
- createVaporApp({
- render() {
- return createComponent(
- Comp,
- {},
- { default: () => template('msg')() },
- )!
- },
- })
- }
- const App = {
- setup() {
- mountComp()
- return []
- },
- }
- createVaporApp(App).mount(document.createElement('div'))
- expect(
- 'Slot "default" invoked outside of the render function',
- ).not.toHaveBeenWarned()
- })
- describe('createSlot', () => {
- test('slot should be rendered correctly', () => {
- const Comp = defineVaporComponent(() => {
- const n0 = template('<div>')()
- insert(createSlot('header'), n0 as any as ParentNode)
- return n0
- })
- const { host } = define(() => {
- return createComponent(Comp, null, {
- header: withVaporCtx(() => template('header')()),
- })
- }).render()
- expect(host.innerHTML).toBe('<div>header<!--slot--></div>')
- })
- test('slot should be rendered correctly with slot props', async () => {
- const src = ref('header')
- const Comp = defineVaporComponent(() => {
- const n0 = template('<div></div>')()
- insert(
- createSlot('header', { title: () => src.value }),
- n0 as any as ParentNode,
- )
- return n0
- })
- const { host } = define(() => {
- return createComponent(Comp, null, {
- header: props => {
- const el = template('<h1></h1>')()
- renderEffect(() => {
- setElementText(el, props.title)
- })
- return el
- },
- })
- }).render()
- expect(host.innerHTML).toBe('<div><h1>header</h1><!--slot--></div>')
- src.value = 'footer'
- await nextTick()
- expect(host.innerHTML).toBe('<div><h1>footer</h1><!--slot--></div>')
- })
- test('dynamic slot props', async () => {
- let props: any
- const bindObj = ref<Record<string, any>>({ foo: 1, baz: 'qux' })
- const Comp = defineVaporComponent(() =>
- createSlot('default', { $: [() => bindObj.value] }),
- )
- define(() =>
- createComponent(Comp, null, {
- default: withVaporCtx((_props: any) => ((props = _props), [])),
- }),
- ).render()
- expect(props).toEqual({ foo: 1, baz: 'qux' })
- bindObj.value.foo = 2
- await nextTick()
- expect(props).toEqual({ foo: 2, baz: 'qux' })
- delete bindObj.value.baz
- await nextTick()
- expect(props).toEqual({ foo: 2 })
- })
- test('dynamic slot props with static slot props', async () => {
- let props: any
- const foo = ref(0)
- const bindObj = ref<Record<string, any>>({ foo: 100, baz: 'qux' })
- const Comp = defineVaporComponent(() =>
- createSlot('default', {
- foo: () => foo.value,
- $: [() => bindObj.value],
- }),
- )
- define(() =>
- createComponent(Comp, null, {
- default: withVaporCtx((_props: any) => ((props = _props), [])),
- }),
- ).render()
- expect(props).toEqual({ foo: 100, baz: 'qux' })
- foo.value = 2
- await nextTick()
- expect(props).toEqual({ foo: 100, baz: 'qux' })
- delete bindObj.value.foo
- await nextTick()
- expect(props).toEqual({ foo: 2, baz: 'qux' })
- })
- test('dynamic slot should be rendered correctly with slot props', async () => {
- const val = ref('header')
- const Comp = defineVaporComponent(() => {
- const n0 = template('<div></div>')()
- prepend(
- n0 as any as ParentNode,
- createSlot('header', { title: () => val.value }),
- )
- return n0
- })
- const { host } = define(() => {
- // dynamic slot
- return createComponent(Comp, null, {
- $: [
- () => ({
- name: 'header',
- fn: withVaporCtx((props: any) => {
- const el = template('<h1></h1>')()
- renderEffect(() => {
- setElementText(el, props.title)
- })
- return el
- }),
- }),
- ],
- })
- }).render()
- expect(host.innerHTML).toBe('<div><h1>header</h1><!--slot--></div>')
- val.value = 'footer'
- await nextTick()
- expect(host.innerHTML).toBe('<div><h1>footer</h1><!--slot--></div>')
- })
- test('dynamic slot outlet should be render correctly with slot props', async () => {
- const val = ref('header')
- const Comp = defineVaporComponent(() => {
- const n0 = template('<div></div>')()
- prepend(
- n0 as any as ParentNode,
- createSlot(
- () => val.value, // dynamic slot outlet name
- ),
- )
- return n0
- })
- const { host } = define(() => {
- return createComponent(Comp, null, {
- header: withVaporCtx(() => template('header')()),
- footer: withVaporCtx(() => template('footer')()),
- })
- }).render()
- expect(host.innerHTML).toBe('<div>header<!--slot--></div>')
- val.value = 'footer'
- await nextTick()
- expect(host.innerHTML).toBe('<div>footer<!--slot--></div>')
- })
- test('fallback should be render correctly', () => {
- const Comp = defineVaporComponent(() => {
- const n0 = template('<div></div>')()
- insert(
- createSlot('header', undefined, () => template('fallback')()),
- n0 as any as ParentNode,
- )
- return n0
- })
- const { host } = define(() => {
- return createComponent(Comp, {}, {})
- }).render()
- expect(host.innerHTML).toBe('<div>fallback<!--slot--></div>')
- })
- test('dynamic slot should be updated correctly', async () => {
- const flag1 = ref(true)
- const Child = defineVaporComponent(() => {
- const temp0 = template('<p></p>')
- const el0 = temp0()
- const el1 = temp0()
- const slot1 = createSlot('one', null, () => template('one fallback')())
- const slot2 = createSlot('two', null, () => template('two fallback')())
- insert(slot1, el0 as any as ParentNode)
- insert(slot2, el1 as any as ParentNode)
- return [el0, el1]
- })
- const { host } = define(() => {
- return createComponent(Child, null, {
- $: [
- () =>
- flag1.value
- ? {
- name: 'one',
- fn: withVaporCtx(() => template('one content')()),
- }
- : {
- name: 'two',
- fn: withVaporCtx(() => template('two content')()),
- },
- ],
- })
- }).render()
- expect(host.innerHTML).toBe(
- '<p>one content<!--slot--></p><p>two fallback<!--slot--></p>',
- )
- flag1.value = false
- await nextTick()
- expect(host.innerHTML).toBe(
- '<p>one fallback<!--slot--></p><p>two content<!--slot--></p>',
- )
- flag1.value = true
- await nextTick()
- expect(host.innerHTML).toBe(
- '<p>one content<!--slot--></p><p>two fallback<!--slot--></p>',
- )
- })
- test('dynamic slot outlet should be updated correctly', async () => {
- const slotOutletName = ref('one')
- const Child = defineVaporComponent(() => {
- const temp0 = template('<p>')
- const el0 = temp0()
- const slot1 = createSlot(
- () => slotOutletName.value,
- undefined,
- () => template('fallback')(),
- )
- insert(slot1, el0 as any as ParentNode)
- return el0
- })
- const { host } = define(() => {
- return createComponent(
- Child,
- {},
- {
- one: withVaporCtx(() => template('one content')()),
- two: withVaporCtx(() => template('two content')()),
- },
- )
- }).render()
- expect(host.innerHTML).toBe('<p>one content<!--slot--></p>')
- slotOutletName.value = 'two'
- await nextTick()
- expect(host.innerHTML).toBe('<p>two content<!--slot--></p>')
- slotOutletName.value = 'none'
- await nextTick()
- expect(host.innerHTML).toBe('<p>fallback<!--slot--></p>')
- })
- test('non-exist slot', async () => {
- const Child = defineVaporComponent(() => {
- const el0 = template('<p>')()
- const slot = createSlot('not-exist', undefined)
- insert(slot, el0 as any as ParentNode)
- return el0
- })
- const { host } = define(() => {
- return createComponent(Child)
- }).render()
- expect(host.innerHTML).toBe('<p><!--slot--></p>')
- })
- test('use fallback when inner content changes', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const toggle = ref(true)
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- return createIf(
- () => toggle.value,
- () => {
- return document.createTextNode('content')
- },
- )
- }),
- })
- },
- }).render()
- expect(html()).toBe('content<!--if--><!--slot-->')
- toggle.value = false
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- toggle.value = true
- await nextTick()
- expect(html()).toBe('content<!--if--><!--slot-->')
- })
- test('use fallback on initial render', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const toggle = ref(false)
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- return createIf(
- () => toggle.value,
- () => {
- return document.createTextNode('content')
- },
- )
- }),
- })
- },
- }).render()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- toggle.value = true
- await nextTick()
- expect(html()).toBe('content<!--if--><!--slot-->')
- toggle.value = false
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- })
- test('dynamic slot work with v-if', async () => {
- const val = ref('header')
- const toggle = ref(false)
- const Comp = defineVaporComponent(() => {
- const n0 = template('<div></div>')()
- prepend(n0 as any as ParentNode, createSlot('header', null))
- return n0
- })
- const { host } = define(() => {
- // dynamic slot
- return createComponent(Comp, null, {
- $: [
- () =>
- (toggle.value
- ? {
- name: val.value,
- fn: withVaporCtx(() => {
- return template('<h1></h1>')()
- }),
- }
- : void 0) as DynamicSlot,
- ],
- })
- }).render()
- expect(host.innerHTML).toBe('<div><!--slot--></div>')
- toggle.value = true
- await nextTick()
- expect(host.innerHTML).toBe('<div><h1></h1><!--slot--></div>')
- })
- test('render fallback when slot content is not valid', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- return template('<!--comment-->')()
- }),
- })
- },
- }).render()
- expect(html()).toBe('fallback<!--slot-->')
- })
- test('render fallback when v-if condition is false', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const toggle = ref(false)
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- return createIf(
- () => toggle.value,
- () => {
- return document.createTextNode('content')
- },
- )
- }),
- })
- },
- }).render()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- toggle.value = true
- await nextTick()
- expect(html()).toBe('content<!--if--><!--slot-->')
- toggle.value = false
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- })
- test('render fallback with nested v-if', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const outerShow = ref(false)
- const innerShow = ref(false)
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- return createIf(
- () => outerShow.value,
- () => {
- return createIf(
- () => innerShow.value,
- () => {
- return document.createTextNode('content')
- },
- )
- },
- )
- }),
- })
- },
- }).render()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- outerShow.value = true
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
- innerShow.value = true
- await nextTick()
- expect(html()).toBe('content<!--if--><!--if--><!--slot-->')
- innerShow.value = false
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
- outerShow.value = false
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--slot-->')
- outerShow.value = true
- await nextTick()
- expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
- innerShow.value = true
- await nextTick()
- expect(html()).toBe('content<!--if--><!--if--><!--slot-->')
- })
- test('render fallback with v-for', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const items = ref<number[]>([1])
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- const n2 = createFor(
- () => items.value,
- for_item0 => {
- const n4 = template('<span> </span>')() as any
- const x4 = child(n4) as any
- renderEffect(() =>
- setText(x4, toDisplayString(for_item0.value)),
- )
- return n4
- },
- )
- return n2
- }),
- })
- },
- }).render()
- expect(html()).toBe('<span>1</span><!--for--><!--slot-->')
- items.value.pop()
- await nextTick()
- expect(html()).toBe('fallback<!--for--><!--slot-->')
- items.value.pop()
- await nextTick()
- expect(html()).toBe('fallback<!--for--><!--slot-->')
- items.value.push(2)
- await nextTick()
- expect(html()).toBe('<span>2</span><!--for--><!--slot-->')
- })
- test('render fallback with v-for (empty source)', async () => {
- const Child = {
- setup() {
- return createSlot('default', null, () =>
- document.createTextNode('fallback'),
- )
- },
- }
- const items = ref<number[]>([])
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- const n2 = createFor(
- () => items.value,
- for_item0 => {
- const n4 = template('<span> </span>')() as any
- const x4 = child(n4) as any
- renderEffect(() =>
- setText(x4, toDisplayString(for_item0.value)),
- )
- return n4
- },
- )
- return n2
- }),
- })
- },
- }).render()
- expect(html()).toBe('fallback<!--for--><!--slot-->')
- items.value.push(1)
- await nextTick()
- expect(html()).toBe('<span>1</span><!--for--><!--slot-->')
- items.value.pop()
- await nextTick()
- expect(html()).toBe('fallback<!--for--><!--slot-->')
- items.value.pop()
- await nextTick()
- expect(html()).toBe('fallback<!--for--><!--slot-->')
- items.value.push(2)
- await nextTick()
- expect(html()).toBe('<span>2</span><!--for--><!--slot-->')
- })
- test('work with v-once', async () => {
- const Child = defineVaporComponent({
- setup() {
- return createSlot(
- 'default',
- null,
- undefined,
- undefined,
- true /* once */,
- )
- },
- })
- const count = ref(0)
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => {
- const n3 = template('<div> </div>')() as any
- const x3 = txt(n3) as any
- renderEffect(() => setText(x3, toDisplayString(count.value)))
- return n3
- }),
- })
- },
- }).render()
- expect(html()).toBe('<div>0</div><!--slot-->')
- // expect no changes due to v-once
- count.value++
- await nextTick()
- expect(html()).toBe('<div>0</div><!--slot-->')
- })
- })
- describe('forwarded slot', () => {
- test('should work', async () => {
- const Child = defineVaporComponent({
- setup() {
- return createSlot('foo', null)
- },
- })
- const Parent = defineVaporComponent({
- setup() {
- const n2 = createComponent(
- Child,
- null,
- {
- foo: withVaporCtx(() => {
- return createSlot('foo', null)
- }),
- },
- true,
- )
- return n2
- },
- })
- const foo = ref('foo')
- const { host } = define({
- setup() {
- const n2 = createComponent(
- Parent,
- null,
- {
- foo: withVaporCtx(() => {
- const n0 = template(' ')() as any
- renderEffect(() => setText(n0, foo.value))
- return n0
- }),
- },
- true,
- )
- return n2
- },
- }).render()
- expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
- })
- test('mixed with non-forwarded slot', async () => {
- const Child = defineVaporComponent({
- setup() {
- return [createSlot('foo', null)]
- },
- })
- const Parent = defineVaporComponent({
- setup() {
- const n2 = createComponent(Child, null, {
- foo: withVaporCtx(() => {
- const n0 = createSlot('foo', null)
- return n0
- }),
- })
- const n3 = createSlot('default', null)
- return [n2, n3]
- },
- })
- const foo = ref('foo')
- const { host } = define({
- setup() {
- const n2 = createComponent(
- Parent,
- null,
- {
- foo: withVaporCtx(() => {
- const n0 = template(' ')() as any
- renderEffect(() => setText(n0, foo.value))
- return n0
- }),
- default: withVaporCtx(() => {
- const n3 = template(' ')() as any
- renderEffect(() => setText(n3, foo.value))
- return n3
- }),
- },
- true,
- )
- return n2
- },
- }).render()
- expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->foo<!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->bar<!--slot-->')
- })
- test('forwarded slot with fallback', async () => {
- const Child = defineVaporComponent({
- setup() {
- return createSlot('default', null, () => template('child fallback')())
- },
- })
- const Parent = defineVaporComponent({
- setup() {
- const n2 = createComponent(Child, null, {
- default: withVaporCtx(() => {
- const n0 = createSlot('default', null, () => {
- return template('<!-- <div></div> -->')()
- })
- return n0
- }),
- })
- return n2
- },
- })
- const { html } = define({
- setup() {
- return createComponent(Parent, null, {
- default: withVaporCtx(() => template('<!-- <div>App</div> -->')()),
- })
- },
- }).render()
- expect(html()).toBe('child fallback<!--slot--><!--slot-->')
- })
- test('forwarded slot with fallback (v-if)', async () => {
- const Child = defineVaporComponent({
- setup() {
- return createSlot('default', null, () => template('child fallback')())
- },
- })
- const show = ref(false)
- const Parent = defineVaporComponent({
- setup() {
- const n2 = createComponent(Child, null, {
- default: withVaporCtx(() => {
- const n0 = createSlot('default', null, () => {
- const n2 = createIf(
- () => show.value,
- () => {
- const n4 = template('<div>if content</div>')()
- return n4
- },
- )
- return n2
- })
- return n0
- }),
- })
- return n2
- },
- })
- const { html } = define({
- setup() {
- return createComponent(Parent, null, {
- default: withVaporCtx(() => template('<!-- <div>App</div> -->')()),
- })
- },
- }).render()
- expect(html()).toBe('child fallback<!--if--><!--slot--><!--slot-->')
- show.value = true
- await nextTick()
- expect(html()).toBe(
- '<div>if content</div><!--if--><!--slot--><!--slot-->',
- )
- })
- test('forwarded slot with fallback (v-for)', async () => {
- const Child = defineVaporComponent({
- setup() {
- return createSlot('default', null, () => template('child fallback')())
- },
- })
- const items = ref<number[]>([])
- const Parent = defineVaporComponent({
- setup() {
- const n2 = createComponent(Child, null, {
- default: withVaporCtx(() => {
- const n0 = createSlot('default', null, () => {
- const n2 = createFor(
- () => items.value,
- for_item0 => {
- const n4 = template('<span> </span>')() as any
- const x4 = child(n4) as any
- renderEffect(() =>
- setText(x4, toDisplayString(for_item0.value)),
- )
- return n4
- },
- )
- return n2
- })
- return n0
- }),
- })
- return n2
- },
- })
- const { html } = define({
- setup() {
- return createComponent(Parent, null, {
- default: () => template('<!-- <div>App</div> -->')(),
- })
- },
- }).render()
- expect(html()).toBe('child fallback<!--for--><!--slot--><!--slot-->')
- items.value.push(1)
- await nextTick()
- expect(html()).toBe('<span>1</span><!--for--><!--slot--><!--slot-->')
- items.value.pop()
- await nextTick()
- expect(html()).toBe('child fallback<!--for--><!--slot--><!--slot-->')
- })
- test('consecutive slots with insertion state', async () => {
- const { component: Child } = define({
- setup() {
- const n2 = template('<div><div>baz</div></div>', true)() as any
- setInsertionState(n2, 0)
- createSlot('default', null)
- setInsertionState(n2, 0)
- createSlot('foo', null)
- return n2
- },
- })
- const { html } = define({
- setup() {
- return createComponent(Child, null, {
- default: withVaporCtx(() => template('default')()),
- foo: withVaporCtx(() => template('foo')()),
- })
- },
- }).render()
- expect(html()).toBe(
- `<div>` +
- `default<!--slot-->` +
- `foo<!--slot-->` +
- `<div>baz</div>` +
- `</div>`,
- )
- })
- describe('vdom interop', () => {
- const createVaporSlot = (fallbackText = 'fallback') => {
- return defineVaporComponent({
- setup() {
- const n0 = createSlot('foo', null, () => {
- const n2 = template(`<div>${fallbackText}</div>`)()
- return n2
- })
- return n0
- },
- })
- }
- const createVdomSlot = (fallbackText = 'fallback') => {
- return {
- render(this: any) {
- return renderSlot(this.$slots, 'foo', {}, () => [
- h('div', fallbackText),
- ])
- },
- }
- }
- const createVaporForwardedSlot = (
- targetComponent: any,
- fallbackText?: string,
- ) => {
- return defineVaporComponent({
- setup() {
- const n2 = createComponent(
- targetComponent,
- null,
- {
- foo: withVaporCtx(() => {
- return fallbackText
- ? createSlot('foo', null, () => {
- const n2 = template(`<div>${fallbackText}</div>`)()
- return n2
- })
- : createSlot('foo', null)
- }),
- },
- true,
- )
- return n2
- },
- })
- }
- const createVdomForwardedSlot = (
- targetComponent: any,
- fallbackText?: string,
- ) => {
- return {
- render(this: any) {
- return h(targetComponent, null, {
- foo: () => [
- fallbackText
- ? renderSlot(this.$slots, 'foo', {}, () => [
- h('div', fallbackText),
- ])
- : renderSlot(this.$slots, 'foo'),
- ],
- _: 3 /* FORWARDED */,
- })
- },
- }
- }
- const createMultipleVaporForwardedSlots = (
- targetComponent: any,
- count: number,
- ) => {
- let current = targetComponent
- for (let i = 0; i < count; i++) {
- current = createVaporForwardedSlot(current)
- }
- return current
- }
- const createMultipleVdomForwardedSlots = (
- targetComponent: any,
- count: number,
- ) => {
- let current = targetComponent
- for (let i = 0; i < count; i++) {
- current = createVdomForwardedSlot(current)
- }
- return current
- }
- const createTestApp = (
- rootComponent: any,
- foo: Ref<string>,
- show: Ref<Boolean>,
- ) => {
- return {
- setup() {
- return () =>
- h(
- rootComponent,
- null,
- createSlots({ _: 2 /* DYNAMIC */ } as any, [
- show.value
- ? {
- name: 'foo',
- fn: () => [h('span', foo.value)],
- key: '0',
- }
- : undefined,
- ]),
- )
- },
- }
- }
- const createEmptyTestApp = (rootComponent: any) => {
- return {
- setup() {
- return () => h(rootComponent)
- },
- }
- }
- test('vdom slot > vapor forwarded slot > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
- VaporSlot,
- 'forwarded fallback',
- )
- const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>forwarded fallback</div><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VaporForwardedSlot = createVaporForwardedSlot(VdomSlot)
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
- VdomSlot,
- 'forwarded fallback',
- )
- const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>forwarded fallback</div>')
- })
- test('vdom slot > vapor forwarded slot > vdom forwarded slot > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
- const VaporForwardedSlot = createVaporForwardedSlot(VdomForwardedSlot)
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vdom forwarded slot > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
- const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
- VdomForwardedSlot,
- 'forwarded fallback',
- )
- const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>forwarded fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vapor forwarded slot > vdom forwarded slot(with fallback) > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
- VaporSlot,
- 'vdom fallback',
- )
- const VaporForwardedSlot = createVaporForwardedSlot(
- VdomForwardedSlotWithFallback,
- )
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vdom fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot(empty) > vapor forwarded slot > vdom forwarded slot(with fallback) > vapor slot', async () => {
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
- VaporSlot,
- 'vdom fallback',
- )
- const VaporForwardedSlot = createVaporForwardedSlot(
- VdomForwardedSlotWithFallback,
- )
- const App = createEmptyTestApp(VaporForwardedSlot)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<div>vdom fallback</div>')
- })
- test('vdom slot > vapor forwarded slot > vdom forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
- const VaporForwardedSlot = createVaporForwardedSlot(VdomForwardedSlot)
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vdom forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
- const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
- VdomForwardedSlot,
- 'vapor fallback',
- )
- const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vapor fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vapor forwarded slot > vdom forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
- VdomSlot,
- 'vdom fallback',
- )
- const VaporForwardedSlot = createVaporForwardedSlot(
- VdomForwardedSlotWithFallback,
- )
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vdom fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vapor forwarded slot (multiple) > vdom forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
- const VaporForwardedSlot = createMultipleVaporForwardedSlots(
- VdomForwardedSlot,
- 3,
- )
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div><!--slot--><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot (multiple) > vdom forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
- VdomSlot,
- 'vdom fallback',
- )
- const VaporForwardedSlot = createMultipleVaporForwardedSlots(
- VdomForwardedSlotWithFallback,
- 3,
- )
- const App = createTestApp(VaporForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe(
- '<div>vdom fallback</div><!--slot--><!--slot-->',
- )
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- })
- test('vdom slot > vdom forwarded slot > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
- const App = createTestApp(VdomForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vdom forwarded slot > vapor forwarded slot > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
- const VdomForwardedSlot = createVdomForwardedSlot(VaporForwardedSlot)
- const App = createTestApp(VdomForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vdom forwarded slot (multiple) > vapor forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
- const VdomForwardedSlot = createMultipleVdomForwardedSlots(
- VaporForwardedSlot,
- 3,
- )
- const App = createTestApp(VdomForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vdom forwarded slot (multiple) > vapor forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlot = createVaporForwardedSlot(
- VaporSlot,
- 'vapor fallback',
- )
- const VdomForwardedSlot = createMultipleVdomForwardedSlots(
- VaporForwardedSlot,
- 3,
- )
- const App = createTestApp(VdomForwardedSlot, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vapor fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot > vapor forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VaporForwardedSlot1 = createMultipleVaporForwardedSlots(
- VdomSlot,
- 2,
- )
- const App = createTestApp(VaporForwardedSlot1, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VaporForwardedSlot2 = createVaporForwardedSlot(VdomSlot)
- const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
- VaporForwardedSlot2,
- 'vapor1 fallback',
- )
- const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vapor1 fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot > vapor forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
- VdomSlot,
- 'vapor2 fallback',
- )
- const VaporForwardedSlot1 = createVaporForwardedSlot(
- VaporForwardedSlot2WithFallback,
- )
- const App = createTestApp(VaporForwardedSlot1, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vapor2 fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot > vapor forwarded slot > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlot2 = createVaporForwardedSlot(VaporSlot)
- const VaporForwardedSlot1 =
- createVaporForwardedSlot(VaporForwardedSlot2)
- const App = createTestApp(VaporForwardedSlot1, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>fallback</div><!--slot--><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
- VdomSlot,
- 'vapor2 fallback',
- )
- const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
- VaporForwardedSlot2WithFallback,
- 'vapor1 fallback',
- )
- const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vapor1 fallback</div><!--slot-->')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
- })
- test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot(with fallback) > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
- VaporSlot,
- 'vapor2 fallback',
- )
- const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
- VaporForwardedSlot2WithFallback,
- 'vapor1 fallback',
- )
- const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe(
- '<div>vapor1 fallback</div><!--slot--><!--slot-->',
- )
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
- })
- test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
- VaporSlot,
- 'vdom2 fallback',
- )
- const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
- VdomForwardedSlot2WithFallback,
- 'vdom1 fallback',
- )
- const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) > vdom slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VdomSlot = createVdomSlot()
- const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
- VdomSlot,
- 'vdom2 fallback',
- )
- const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
- VdomForwardedSlot2WithFallback,
- 'vdom1 fallback',
- )
- const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) (multiple) > vapor slot', async () => {
- const foo = ref('foo')
- const show = ref(true)
- const VaporSlot = createVaporSlot()
- const VdomForwardedSlot3WithFallback = createVdomForwardedSlot(
- VaporSlot,
- 'vdom3 fallback',
- )
- const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
- VdomForwardedSlot3WithFallback,
- 'vdom2 fallback',
- )
- const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
- VdomForwardedSlot2WithFallback,
- 'vdom1 fallback',
- )
- const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
- const root = document.createElement('div')
- createApp(App).use(vaporInteropPlugin).mount(root)
- expect(root.innerHTML).toBe('<span>foo</span>')
- foo.value = 'bar'
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- show.value = false
- await nextTick()
- expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
- show.value = true
- await nextTick()
- expect(root.innerHTML).toBe('<span>bar</span>')
- })
- })
- })
- })
|