componentSlots.spec.ts 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736
  1. // NOTE: This test is implemented based on the case of `runtime-core/__test__/componentSlots.spec.ts`.
  2. import {
  3. child,
  4. createComponent,
  5. createFor,
  6. createForSlots,
  7. createIf,
  8. createSlot,
  9. createVaporApp,
  10. defineVaporComponent,
  11. forwardedSlotCreator,
  12. insert,
  13. prepend,
  14. renderEffect,
  15. setInsertionState,
  16. template,
  17. vaporInteropPlugin,
  18. } from '../src'
  19. import {
  20. type Ref,
  21. createApp,
  22. createSlots,
  23. currentInstance,
  24. h,
  25. nextTick,
  26. ref,
  27. renderSlot,
  28. toDisplayString,
  29. } from '@vue/runtime-dom'
  30. import { makeRender } from './_utils'
  31. import type { DynamicSlot } from '../src/componentSlots'
  32. import { setElementText, setText } from '../src/dom/prop'
  33. const define = makeRender<any>()
  34. function renderWithSlots(slots: any): any {
  35. let instance: any
  36. const Comp = defineVaporComponent({
  37. setup() {
  38. const t0 = template('<div></div>')
  39. const n0 = t0()
  40. instance = currentInstance
  41. return n0
  42. },
  43. })
  44. const { render } = define({
  45. render() {
  46. return createComponent(Comp, {}, slots)
  47. },
  48. })
  49. render()
  50. return instance
  51. }
  52. describe('component: slots', () => {
  53. test('initSlots: instance.slots should be set correctly', () => {
  54. const { slots } = renderWithSlots({
  55. default: () => template('<span></span>')(),
  56. })
  57. expect(slots.default()).toMatchObject(document.createElement('span'))
  58. })
  59. test('updateSlots: instance.slots should be updated correctly', async () => {
  60. const flag1 = ref(true)
  61. let instance: any
  62. const Child = () => {
  63. instance = currentInstance
  64. return template('child')()
  65. }
  66. const { render } = define({
  67. render() {
  68. return createComponent(
  69. Child,
  70. {},
  71. {
  72. $: [
  73. () =>
  74. flag1.value
  75. ? { name: 'one', fn: () => template('<span></span>')() }
  76. : { name: 'two', fn: () => template('<div></div>')() },
  77. ],
  78. },
  79. )
  80. },
  81. })
  82. render()
  83. expect(instance.slots).toHaveProperty('one')
  84. expect(instance.slots).not.toHaveProperty('two')
  85. flag1.value = false
  86. await nextTick()
  87. expect(instance.slots).not.toHaveProperty('one')
  88. expect(instance.slots).toHaveProperty('two')
  89. })
  90. test('should work with createFlorSlots', async () => {
  91. const loop = ref([1, 2, 3])
  92. let instance: any
  93. const Child = () => {
  94. instance = currentInstance
  95. return template('child')()
  96. }
  97. const { render } = define({
  98. setup() {
  99. return createComponent(Child, null, {
  100. $: [
  101. () =>
  102. createForSlots(loop.value, (item, i) => ({
  103. name: item,
  104. fn: () => template(item + i)(),
  105. })),
  106. ],
  107. })
  108. },
  109. })
  110. render()
  111. expect(instance.slots).toHaveProperty('1')
  112. expect(instance.slots).toHaveProperty('2')
  113. expect(instance.slots).toHaveProperty('3')
  114. loop.value.push(4)
  115. await nextTick()
  116. expect(instance.slots).toHaveProperty('4')
  117. loop.value.shift()
  118. await nextTick()
  119. expect(instance.slots).not.toHaveProperty('1')
  120. })
  121. // passes but no warning for slot invocation in vapor currently
  122. test.todo('should not warn when mounting another app in setup', () => {
  123. const Comp = defineVaporComponent({
  124. setup(_, { slots }) {
  125. return slots.default!()
  126. },
  127. })
  128. const mountComp = () => {
  129. createVaporApp({
  130. render() {
  131. return createComponent(
  132. Comp,
  133. {},
  134. { default: () => template('msg')() },
  135. )!
  136. },
  137. })
  138. }
  139. const App = {
  140. setup() {
  141. mountComp()
  142. return []
  143. },
  144. }
  145. createVaporApp(App).mount(document.createElement('div'))
  146. expect(
  147. 'Slot "default" invoked outside of the render function',
  148. ).not.toHaveBeenWarned()
  149. })
  150. describe('createSlot', () => {
  151. test('slot should be rendered correctly', () => {
  152. const Comp = defineVaporComponent(() => {
  153. const n0 = template('<div>')()
  154. insert(createSlot('header'), n0 as any as ParentNode)
  155. return n0
  156. })
  157. const { host } = define(() => {
  158. return createComponent(Comp, null, {
  159. header: () => template('header')(),
  160. })
  161. }).render()
  162. expect(host.innerHTML).toBe('<div>header<!--slot--></div>')
  163. })
  164. test('slot should be rendered correctly with slot props', async () => {
  165. const src = ref('header')
  166. const Comp = defineVaporComponent(() => {
  167. const n0 = template('<div></div>')()
  168. insert(
  169. createSlot('header', { title: () => src.value }),
  170. n0 as any as ParentNode,
  171. )
  172. return n0
  173. })
  174. const { host } = define(() => {
  175. return createComponent(Comp, null, {
  176. header: props => {
  177. const el = template('<h1></h1>')()
  178. renderEffect(() => {
  179. setElementText(el, props.title)
  180. })
  181. return el
  182. },
  183. })
  184. }).render()
  185. expect(host.innerHTML).toBe('<div><h1>header</h1><!--slot--></div>')
  186. src.value = 'footer'
  187. await nextTick()
  188. expect(host.innerHTML).toBe('<div><h1>footer</h1><!--slot--></div>')
  189. })
  190. test('dynamic slot props', async () => {
  191. let props: any
  192. const bindObj = ref<Record<string, any>>({ foo: 1, baz: 'qux' })
  193. const Comp = defineVaporComponent(() =>
  194. createSlot('default', { $: [() => bindObj.value] }),
  195. )
  196. define(() =>
  197. createComponent(Comp, null, {
  198. default: _props => ((props = _props), []),
  199. }),
  200. ).render()
  201. expect(props).toEqual({ foo: 1, baz: 'qux' })
  202. bindObj.value.foo = 2
  203. await nextTick()
  204. expect(props).toEqual({ foo: 2, baz: 'qux' })
  205. delete bindObj.value.baz
  206. await nextTick()
  207. expect(props).toEqual({ foo: 2 })
  208. })
  209. test('dynamic slot props with static slot props', async () => {
  210. let props: any
  211. const foo = ref(0)
  212. const bindObj = ref<Record<string, any>>({ foo: 100, baz: 'qux' })
  213. const Comp = defineVaporComponent(() =>
  214. createSlot('default', {
  215. foo: () => foo.value,
  216. $: [() => bindObj.value],
  217. }),
  218. )
  219. define(() =>
  220. createComponent(Comp, null, {
  221. default: _props => ((props = _props), []),
  222. }),
  223. ).render()
  224. expect(props).toEqual({ foo: 100, baz: 'qux' })
  225. foo.value = 2
  226. await nextTick()
  227. expect(props).toEqual({ foo: 100, baz: 'qux' })
  228. delete bindObj.value.foo
  229. await nextTick()
  230. expect(props).toEqual({ foo: 2, baz: 'qux' })
  231. })
  232. test('dynamic slot should be rendered correctly with slot props', async () => {
  233. const val = ref('header')
  234. const Comp = defineVaporComponent(() => {
  235. const n0 = template('<div></div>')()
  236. prepend(
  237. n0 as any as ParentNode,
  238. createSlot('header', { title: () => val.value }),
  239. )
  240. return n0
  241. })
  242. const { host } = define(() => {
  243. // dynamic slot
  244. return createComponent(Comp, null, {
  245. $: [
  246. () => ({
  247. name: 'header',
  248. fn: (props: any) => {
  249. const el = template('<h1></h1>')()
  250. renderEffect(() => {
  251. setElementText(el, props.title)
  252. })
  253. return el
  254. },
  255. }),
  256. ],
  257. })
  258. }).render()
  259. expect(host.innerHTML).toBe('<div><h1>header</h1><!--slot--></div>')
  260. val.value = 'footer'
  261. await nextTick()
  262. expect(host.innerHTML).toBe('<div><h1>footer</h1><!--slot--></div>')
  263. })
  264. test('dynamic slot outlet should be render correctly with slot props', async () => {
  265. const val = ref('header')
  266. const Comp = defineVaporComponent(() => {
  267. const n0 = template('<div></div>')()
  268. prepend(
  269. n0 as any as ParentNode,
  270. createSlot(
  271. () => val.value, // dynamic slot outlet name
  272. ),
  273. )
  274. return n0
  275. })
  276. const { host } = define(() => {
  277. return createComponent(Comp, null, {
  278. header: () => template('header')(),
  279. footer: () => template('footer')(),
  280. })
  281. }).render()
  282. expect(host.innerHTML).toBe('<div>header<!--slot--></div>')
  283. val.value = 'footer'
  284. await nextTick()
  285. expect(host.innerHTML).toBe('<div>footer<!--slot--></div>')
  286. })
  287. test('fallback should be render correctly', () => {
  288. const Comp = defineVaporComponent(() => {
  289. const n0 = template('<div></div>')()
  290. insert(
  291. createSlot('header', undefined, () => template('fallback')()),
  292. n0 as any as ParentNode,
  293. )
  294. return n0
  295. })
  296. const { host } = define(() => {
  297. return createComponent(Comp, {}, {})
  298. }).render()
  299. expect(host.innerHTML).toBe('<div>fallback<!--slot--></div>')
  300. })
  301. test('dynamic slot should be updated correctly', async () => {
  302. const flag1 = ref(true)
  303. const Child = defineVaporComponent(() => {
  304. const temp0 = template('<p></p>')
  305. const el0 = temp0()
  306. const el1 = temp0()
  307. const slot1 = createSlot('one', null, () => template('one fallback')())
  308. const slot2 = createSlot('two', null, () => template('two fallback')())
  309. insert(slot1, el0 as any as ParentNode)
  310. insert(slot2, el1 as any as ParentNode)
  311. return [el0, el1]
  312. })
  313. const { host } = define(() => {
  314. return createComponent(Child, null, {
  315. $: [
  316. () =>
  317. flag1.value
  318. ? { name: 'one', fn: () => template('one content')() }
  319. : { name: 'two', fn: () => template('two content')() },
  320. ],
  321. })
  322. }).render()
  323. expect(host.innerHTML).toBe(
  324. '<p>one content<!--slot--></p><p>two fallback<!--slot--></p>',
  325. )
  326. flag1.value = false
  327. await nextTick()
  328. expect(host.innerHTML).toBe(
  329. '<p>one fallback<!--slot--></p><p>two content<!--slot--></p>',
  330. )
  331. flag1.value = true
  332. await nextTick()
  333. expect(host.innerHTML).toBe(
  334. '<p>one content<!--slot--></p><p>two fallback<!--slot--></p>',
  335. )
  336. })
  337. test('dynamic slot outlet should be updated correctly', async () => {
  338. const slotOutletName = ref('one')
  339. const Child = defineVaporComponent(() => {
  340. const temp0 = template('<p>')
  341. const el0 = temp0()
  342. const slot1 = createSlot(
  343. () => slotOutletName.value,
  344. undefined,
  345. () => template('fallback')(),
  346. )
  347. insert(slot1, el0 as any as ParentNode)
  348. return el0
  349. })
  350. const { host } = define(() => {
  351. return createComponent(
  352. Child,
  353. {},
  354. {
  355. one: () => template('one content')(),
  356. two: () => template('two content')(),
  357. },
  358. )
  359. }).render()
  360. expect(host.innerHTML).toBe('<p>one content<!--slot--></p>')
  361. slotOutletName.value = 'two'
  362. await nextTick()
  363. expect(host.innerHTML).toBe('<p>two content<!--slot--></p>')
  364. slotOutletName.value = 'none'
  365. await nextTick()
  366. expect(host.innerHTML).toBe('<p>fallback<!--slot--></p>')
  367. })
  368. test('non-exist slot', async () => {
  369. const Child = defineVaporComponent(() => {
  370. const el0 = template('<p>')()
  371. const slot = createSlot('not-exist', undefined)
  372. insert(slot, el0 as any as ParentNode)
  373. return el0
  374. })
  375. const { host } = define(() => {
  376. return createComponent(Child)
  377. }).render()
  378. expect(host.innerHTML).toBe('<p><!--slot--></p>')
  379. })
  380. test('use fallback when inner content changes', async () => {
  381. const Child = {
  382. setup() {
  383. return createSlot('default', null, () =>
  384. document.createTextNode('fallback'),
  385. )
  386. },
  387. }
  388. const toggle = ref(true)
  389. const { html } = define({
  390. setup() {
  391. return createComponent(Child, null, {
  392. default: () => {
  393. return createIf(
  394. () => toggle.value,
  395. () => {
  396. return document.createTextNode('content')
  397. },
  398. )
  399. },
  400. })
  401. },
  402. }).render()
  403. expect(html()).toBe('content<!--if--><!--slot-->')
  404. toggle.value = false
  405. await nextTick()
  406. expect(html()).toBe('fallback<!--if--><!--slot-->')
  407. toggle.value = true
  408. await nextTick()
  409. expect(html()).toBe('content<!--if--><!--slot-->')
  410. })
  411. test('use fallback on initial render', async () => {
  412. const Child = {
  413. setup() {
  414. return createSlot('default', null, () =>
  415. document.createTextNode('fallback'),
  416. )
  417. },
  418. }
  419. const toggle = ref(false)
  420. const { html } = define({
  421. setup() {
  422. return createComponent(Child, null, {
  423. default: () => {
  424. return createIf(
  425. () => toggle.value,
  426. () => {
  427. return document.createTextNode('content')
  428. },
  429. )
  430. },
  431. })
  432. },
  433. }).render()
  434. expect(html()).toBe('fallback<!--if--><!--slot-->')
  435. toggle.value = true
  436. await nextTick()
  437. expect(html()).toBe('content<!--if--><!--slot-->')
  438. toggle.value = false
  439. await nextTick()
  440. expect(html()).toBe('fallback<!--if--><!--slot-->')
  441. })
  442. test('dynamic slot work with v-if', async () => {
  443. const val = ref('header')
  444. const toggle = ref(false)
  445. const Comp = defineVaporComponent(() => {
  446. const n0 = template('<div></div>')()
  447. prepend(n0 as any as ParentNode, createSlot('header', null))
  448. return n0
  449. })
  450. const { host } = define(() => {
  451. // dynamic slot
  452. return createComponent(Comp, null, {
  453. $: [
  454. () =>
  455. (toggle.value
  456. ? {
  457. name: val.value,
  458. fn: () => {
  459. return template('<h1></h1>')()
  460. },
  461. }
  462. : void 0) as DynamicSlot,
  463. ],
  464. })
  465. }).render()
  466. expect(host.innerHTML).toBe('<div><!--slot--></div>')
  467. toggle.value = true
  468. await nextTick()
  469. expect(host.innerHTML).toBe('<div><h1></h1><!--slot--></div>')
  470. })
  471. test('render fallback when slot content is not valid', async () => {
  472. const Child = {
  473. setup() {
  474. return createSlot('default', null, () =>
  475. document.createTextNode('fallback'),
  476. )
  477. },
  478. }
  479. const { html } = define({
  480. setup() {
  481. return createComponent(Child, null, {
  482. default: () => {
  483. return template('<!--comment-->')()
  484. },
  485. })
  486. },
  487. }).render()
  488. expect(html()).toBe('fallback<!--slot-->')
  489. })
  490. test('render fallback when v-if condition is false', async () => {
  491. const Child = {
  492. setup() {
  493. return createSlot('default', null, () =>
  494. document.createTextNode('fallback'),
  495. )
  496. },
  497. }
  498. const toggle = ref(false)
  499. const { html } = define({
  500. setup() {
  501. return createComponent(Child, null, {
  502. default: () => {
  503. return createIf(
  504. () => toggle.value,
  505. () => {
  506. return document.createTextNode('content')
  507. },
  508. )
  509. },
  510. })
  511. },
  512. }).render()
  513. expect(html()).toBe('fallback<!--if--><!--slot-->')
  514. toggle.value = true
  515. await nextTick()
  516. expect(html()).toBe('content<!--if--><!--slot-->')
  517. toggle.value = false
  518. await nextTick()
  519. expect(html()).toBe('fallback<!--if--><!--slot-->')
  520. })
  521. test('render fallback with nested v-if', async () => {
  522. const Child = {
  523. setup() {
  524. return createSlot('default', null, () =>
  525. document.createTextNode('fallback'),
  526. )
  527. },
  528. }
  529. const outerShow = ref(false)
  530. const innerShow = ref(false)
  531. const { html } = define({
  532. setup() {
  533. return createComponent(Child, null, {
  534. default: () => {
  535. return createIf(
  536. () => outerShow.value,
  537. () => {
  538. return createIf(
  539. () => innerShow.value,
  540. () => {
  541. return document.createTextNode('content')
  542. },
  543. )
  544. },
  545. )
  546. },
  547. })
  548. },
  549. }).render()
  550. expect(html()).toBe('fallback<!--if--><!--slot-->')
  551. outerShow.value = true
  552. await nextTick()
  553. expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
  554. innerShow.value = true
  555. await nextTick()
  556. expect(html()).toBe('content<!--if--><!--if--><!--slot-->')
  557. innerShow.value = false
  558. await nextTick()
  559. expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
  560. outerShow.value = false
  561. await nextTick()
  562. expect(html()).toBe('fallback<!--if--><!--slot-->')
  563. outerShow.value = true
  564. await nextTick()
  565. expect(html()).toBe('fallback<!--if--><!--if--><!--slot-->')
  566. innerShow.value = true
  567. await nextTick()
  568. expect(html()).toBe('content<!--if--><!--if--><!--slot-->')
  569. })
  570. test('render fallback with v-for', async () => {
  571. const Child = {
  572. setup() {
  573. return createSlot('default', null, () =>
  574. document.createTextNode('fallback'),
  575. )
  576. },
  577. }
  578. const items = ref<number[]>([1])
  579. const { html } = define({
  580. setup() {
  581. return createComponent(Child, null, {
  582. default: () => {
  583. const n2 = createFor(
  584. () => items.value,
  585. for_item0 => {
  586. const n4 = template('<span> </span>')() as any
  587. const x4 = child(n4) as any
  588. renderEffect(() =>
  589. setText(x4, toDisplayString(for_item0.value)),
  590. )
  591. return n4
  592. },
  593. )
  594. return n2
  595. },
  596. })
  597. },
  598. }).render()
  599. expect(html()).toBe('<span>1</span><!--for--><!--slot-->')
  600. items.value.pop()
  601. await nextTick()
  602. expect(html()).toBe('fallback<!--for--><!--slot-->')
  603. items.value.pop()
  604. await nextTick()
  605. expect(html()).toBe('fallback<!--for--><!--slot-->')
  606. items.value.push(2)
  607. await nextTick()
  608. expect(html()).toBe('<span>2</span><!--for--><!--slot-->')
  609. })
  610. test('render fallback with v-for (empty source)', async () => {
  611. const Child = {
  612. setup() {
  613. return createSlot('default', null, () =>
  614. document.createTextNode('fallback'),
  615. )
  616. },
  617. }
  618. const items = ref<number[]>([])
  619. const { html } = define({
  620. setup() {
  621. return createComponent(Child, null, {
  622. default: () => {
  623. const n2 = createFor(
  624. () => items.value,
  625. for_item0 => {
  626. const n4 = template('<span> </span>')() as any
  627. const x4 = child(n4) as any
  628. renderEffect(() =>
  629. setText(x4, toDisplayString(for_item0.value)),
  630. )
  631. return n4
  632. },
  633. )
  634. return n2
  635. },
  636. })
  637. },
  638. }).render()
  639. expect(html()).toBe('fallback<!--for--><!--slot-->')
  640. items.value.push(1)
  641. await nextTick()
  642. expect(html()).toBe('<span>1</span><!--for--><!--slot-->')
  643. items.value.pop()
  644. await nextTick()
  645. expect(html()).toBe('fallback<!--for--><!--slot-->')
  646. items.value.pop()
  647. await nextTick()
  648. expect(html()).toBe('fallback<!--for--><!--slot-->')
  649. items.value.push(2)
  650. await nextTick()
  651. expect(html()).toBe('<span>2</span><!--for--><!--slot-->')
  652. })
  653. })
  654. describe('forwarded slot', () => {
  655. test('should work', async () => {
  656. const Child = defineVaporComponent({
  657. setup() {
  658. return createSlot('foo', null)
  659. },
  660. })
  661. const Parent = defineVaporComponent({
  662. setup() {
  663. const createForwardedSlot = forwardedSlotCreator()
  664. const n2 = createComponent(
  665. Child,
  666. null,
  667. {
  668. foo: () => {
  669. return createForwardedSlot('foo', null)
  670. },
  671. },
  672. true,
  673. )
  674. return n2
  675. },
  676. })
  677. const foo = ref('foo')
  678. const { host } = define({
  679. setup() {
  680. const n2 = createComponent(
  681. Parent,
  682. null,
  683. {
  684. foo: () => {
  685. const n0 = template(' ')() as any
  686. renderEffect(() => setText(n0, foo.value))
  687. return n0
  688. },
  689. },
  690. true,
  691. )
  692. return n2
  693. },
  694. }).render()
  695. expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->')
  696. foo.value = 'bar'
  697. await nextTick()
  698. expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
  699. })
  700. test('mixed with non-forwarded slot', async () => {
  701. const Child = defineVaporComponent({
  702. setup() {
  703. return [createSlot('foo', null)]
  704. },
  705. })
  706. const Parent = defineVaporComponent({
  707. setup() {
  708. const createForwardedSlot = forwardedSlotCreator()
  709. const n2 = createComponent(Child, null, {
  710. foo: () => {
  711. const n0 = createForwardedSlot('foo', null)
  712. return n0
  713. },
  714. })
  715. const n3 = createSlot('default', null)
  716. return [n2, n3]
  717. },
  718. })
  719. const foo = ref('foo')
  720. const { host } = define({
  721. setup() {
  722. const n2 = createComponent(
  723. Parent,
  724. null,
  725. {
  726. foo: () => {
  727. const n0 = template(' ')() as any
  728. renderEffect(() => setText(n0, foo.value))
  729. return n0
  730. },
  731. default: () => {
  732. const n3 = template(' ')() as any
  733. renderEffect(() => setText(n3, foo.value))
  734. return n3
  735. },
  736. },
  737. true,
  738. )
  739. return n2
  740. },
  741. }).render()
  742. expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->foo<!--slot-->')
  743. foo.value = 'bar'
  744. await nextTick()
  745. expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->bar<!--slot-->')
  746. })
  747. describe('vdom interop', () => {
  748. const createVaporSlot = (fallbackText = 'fallback') => {
  749. return defineVaporComponent({
  750. setup() {
  751. const n0 = createSlot('foo', null, () => {
  752. const n2 = template(`<div>${fallbackText}</div>`)()
  753. return n2
  754. })
  755. return n0
  756. },
  757. })
  758. }
  759. const createVdomSlot = (fallbackText = 'fallback') => {
  760. return {
  761. render(this: any) {
  762. return renderSlot(this.$slots, 'foo', {}, () => [
  763. h('div', fallbackText),
  764. ])
  765. },
  766. }
  767. }
  768. const createVaporForwardedSlot = (
  769. targetComponent: any,
  770. fallbackText?: string,
  771. ) => {
  772. return defineVaporComponent({
  773. setup() {
  774. const createForwardedSlot = forwardedSlotCreator()
  775. const n2 = createComponent(
  776. targetComponent,
  777. null,
  778. {
  779. foo: () => {
  780. return fallbackText
  781. ? createForwardedSlot('foo', null, () => {
  782. const n2 = template(`<div>${fallbackText}</div>`)()
  783. return n2
  784. })
  785. : createForwardedSlot('foo', null)
  786. },
  787. },
  788. true,
  789. )
  790. return n2
  791. },
  792. })
  793. }
  794. const createVdomForwardedSlot = (
  795. targetComponent: any,
  796. fallbackText?: string,
  797. ) => {
  798. return {
  799. render(this: any) {
  800. return h(targetComponent, null, {
  801. foo: () => [
  802. fallbackText
  803. ? renderSlot(this.$slots, 'foo', {}, () => [
  804. h('div', fallbackText),
  805. ])
  806. : renderSlot(this.$slots, 'foo'),
  807. ],
  808. _: 3 /* FORWARDED */,
  809. })
  810. },
  811. }
  812. }
  813. const createMultipleVaporForwardedSlots = (
  814. targetComponent: any,
  815. count: number,
  816. ) => {
  817. let current = targetComponent
  818. for (let i = 0; i < count; i++) {
  819. current = createVaporForwardedSlot(current)
  820. }
  821. return current
  822. }
  823. const createMultipleVdomForwardedSlots = (
  824. targetComponent: any,
  825. count: number,
  826. ) => {
  827. let current = targetComponent
  828. for (let i = 0; i < count; i++) {
  829. current = createVdomForwardedSlot(current)
  830. }
  831. return current
  832. }
  833. const createTestApp = (
  834. rootComponent: any,
  835. foo: Ref<string>,
  836. show: Ref<Boolean>,
  837. ) => {
  838. return {
  839. setup() {
  840. return () =>
  841. h(
  842. rootComponent,
  843. null,
  844. createSlots({ _: 2 /* DYNAMIC */ } as any, [
  845. show.value
  846. ? {
  847. name: 'foo',
  848. fn: () => [h('span', foo.value)],
  849. key: '0',
  850. }
  851. : undefined,
  852. ]),
  853. )
  854. },
  855. }
  856. }
  857. const createEmptyTestApp = (rootComponent: any) => {
  858. return {
  859. setup() {
  860. return () => h(rootComponent)
  861. },
  862. }
  863. }
  864. test('vdom slot > vapor forwarded slot > vapor slot', async () => {
  865. const foo = ref('foo')
  866. const show = ref(true)
  867. const VaporSlot = createVaporSlot()
  868. const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
  869. const App = createTestApp(VaporForwardedSlot, foo, show)
  870. const root = document.createElement('div')
  871. createApp(App).use(vaporInteropPlugin).mount(root)
  872. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  873. foo.value = 'bar'
  874. await nextTick()
  875. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  876. show.value = false
  877. await nextTick()
  878. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  879. })
  880. test('vdom slot > vapor forwarded slot(with fallback) > vapor slot', async () => {
  881. const foo = ref('foo')
  882. const show = ref(true)
  883. const VaporSlot = createVaporSlot()
  884. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  885. VaporSlot,
  886. 'forwarded fallback',
  887. )
  888. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  889. const root = document.createElement('div')
  890. createApp(App).use(vaporInteropPlugin).mount(root)
  891. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  892. foo.value = 'bar'
  893. await nextTick()
  894. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  895. show.value = false
  896. await nextTick()
  897. expect(root.innerHTML).toBe('<div>forwarded fallback</div><!--slot-->')
  898. })
  899. test('vdom slot > vapor forwarded slot > vdom slot', async () => {
  900. const foo = ref('foo')
  901. const show = ref(true)
  902. const VdomSlot = createVdomSlot()
  903. const VaporForwardedSlot = createVaporForwardedSlot(VdomSlot)
  904. const App = createTestApp(VaporForwardedSlot, foo, show)
  905. const root = document.createElement('div')
  906. createApp(App).use(vaporInteropPlugin).mount(root)
  907. expect(root.innerHTML).toBe('<span>foo</span>')
  908. foo.value = 'bar'
  909. await nextTick()
  910. expect(root.innerHTML).toBe('<span>bar</span>')
  911. show.value = false
  912. await nextTick()
  913. expect(root.innerHTML).toBe('<div>fallback</div>')
  914. show.value = true
  915. await nextTick()
  916. expect(root.innerHTML).toBe('<span>bar</span>')
  917. })
  918. test('vdom slot > vapor forwarded slot(with fallback) > vdom slot', async () => {
  919. const foo = ref('foo')
  920. const show = ref(true)
  921. const VdomSlot = createVdomSlot()
  922. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  923. VdomSlot,
  924. 'forwarded fallback',
  925. )
  926. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  927. const root = document.createElement('div')
  928. createApp(App).use(vaporInteropPlugin).mount(root)
  929. expect(root.innerHTML).toBe('<span>foo</span>')
  930. foo.value = 'bar'
  931. await nextTick()
  932. expect(root.innerHTML).toBe('<span>bar</span>')
  933. show.value = false
  934. await nextTick()
  935. expect(root.innerHTML).toBe('<div>forwarded fallback</div>')
  936. })
  937. test('vdom slot > vapor forwarded slot > vdom forwarded slot > vapor slot', async () => {
  938. const foo = ref('foo')
  939. const show = ref(true)
  940. const VaporSlot = createVaporSlot()
  941. const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
  942. const VaporForwardedSlot = createVaporForwardedSlot(VdomForwardedSlot)
  943. const App = createTestApp(VaporForwardedSlot, foo, show)
  944. const root = document.createElement('div')
  945. createApp(App).use(vaporInteropPlugin).mount(root)
  946. expect(root.innerHTML).toBe('<span>foo</span>')
  947. foo.value = 'bar'
  948. await nextTick()
  949. expect(root.innerHTML).toBe('<span>bar</span>')
  950. show.value = false
  951. await nextTick()
  952. expect(root.innerHTML).toBe('<div>fallback</div>')
  953. show.value = true
  954. await nextTick()
  955. expect(root.innerHTML).toBe('<span>bar</span>')
  956. })
  957. test('vdom slot > vapor forwarded slot(with fallback) > vdom forwarded slot > vapor slot', async () => {
  958. const foo = ref('foo')
  959. const show = ref(true)
  960. const VaporSlot = createVaporSlot()
  961. const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
  962. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  963. VdomForwardedSlot,
  964. 'forwarded fallback',
  965. )
  966. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  967. const root = document.createElement('div')
  968. createApp(App).use(vaporInteropPlugin).mount(root)
  969. expect(root.innerHTML).toBe('<span>foo</span>')
  970. foo.value = 'bar'
  971. await nextTick()
  972. expect(root.innerHTML).toBe('<span>bar</span>')
  973. show.value = false
  974. await nextTick()
  975. expect(root.innerHTML).toBe('<div>forwarded fallback</div>')
  976. show.value = true
  977. await nextTick()
  978. expect(root.innerHTML).toBe('<span>bar</span>')
  979. })
  980. test('vdom slot > vapor forwarded slot > vdom forwarded slot(with fallback) > vapor slot', async () => {
  981. const foo = ref('foo')
  982. const show = ref(true)
  983. const VaporSlot = createVaporSlot()
  984. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  985. VaporSlot,
  986. 'vdom fallback',
  987. )
  988. const VaporForwardedSlot = createVaporForwardedSlot(
  989. VdomForwardedSlotWithFallback,
  990. )
  991. const App = createTestApp(VaporForwardedSlot, foo, show)
  992. const root = document.createElement('div')
  993. createApp(App).use(vaporInteropPlugin).mount(root)
  994. expect(root.innerHTML).toBe('<span>foo</span>')
  995. foo.value = 'bar'
  996. await nextTick()
  997. expect(root.innerHTML).toBe('<span>bar</span>')
  998. show.value = false
  999. await nextTick()
  1000. expect(root.innerHTML).toBe('<div>vdom fallback</div>')
  1001. show.value = true
  1002. await nextTick()
  1003. expect(root.innerHTML).toBe('<span>bar</span>')
  1004. })
  1005. test('vdom slot(empty) > vapor forwarded slot > vdom forwarded slot(with fallback) > vapor slot', async () => {
  1006. const VaporSlot = createVaporSlot()
  1007. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1008. VaporSlot,
  1009. 'vdom fallback',
  1010. )
  1011. const VaporForwardedSlot = createVaporForwardedSlot(
  1012. VdomForwardedSlotWithFallback,
  1013. )
  1014. const App = createEmptyTestApp(VaporForwardedSlot)
  1015. const root = document.createElement('div')
  1016. createApp(App).use(vaporInteropPlugin).mount(root)
  1017. expect(root.innerHTML).toBe('<div>vdom fallback</div>')
  1018. })
  1019. test('vdom slot > vapor forwarded slot > vdom forwarded slot > vdom slot', async () => {
  1020. const foo = ref('foo')
  1021. const show = ref(true)
  1022. const VdomSlot = createVdomSlot()
  1023. const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
  1024. const VaporForwardedSlot = createVaporForwardedSlot(VdomForwardedSlot)
  1025. const App = createTestApp(VaporForwardedSlot, foo, show)
  1026. const root = document.createElement('div')
  1027. createApp(App).use(vaporInteropPlugin).mount(root)
  1028. expect(root.innerHTML).toBe('<span>foo</span>')
  1029. foo.value = 'bar'
  1030. await nextTick()
  1031. expect(root.innerHTML).toBe('<span>bar</span>')
  1032. show.value = false
  1033. await nextTick()
  1034. expect(root.innerHTML).toBe('<div>fallback</div>')
  1035. show.value = true
  1036. await nextTick()
  1037. expect(root.innerHTML).toBe('<span>bar</span>')
  1038. })
  1039. test('vdom slot > vapor forwarded slot(with fallback) > vdom forwarded slot > vdom slot', async () => {
  1040. const foo = ref('foo')
  1041. const show = ref(true)
  1042. const VdomSlot = createVdomSlot()
  1043. const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
  1044. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  1045. VdomForwardedSlot,
  1046. 'vapor fallback',
  1047. )
  1048. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  1049. const root = document.createElement('div')
  1050. createApp(App).use(vaporInteropPlugin).mount(root)
  1051. expect(root.innerHTML).toBe('<span>foo</span>')
  1052. foo.value = 'bar'
  1053. await nextTick()
  1054. expect(root.innerHTML).toBe('<span>bar</span>')
  1055. show.value = false
  1056. await nextTick()
  1057. expect(root.innerHTML).toBe('<div>vapor fallback</div>')
  1058. show.value = true
  1059. await nextTick()
  1060. expect(root.innerHTML).toBe('<span>bar</span>')
  1061. })
  1062. test('vdom slot > vapor forwarded slot > vdom forwarded slot(with fallback) > vdom slot', async () => {
  1063. const foo = ref('foo')
  1064. const show = ref(true)
  1065. const VdomSlot = createVdomSlot()
  1066. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1067. VdomSlot,
  1068. 'vdom fallback',
  1069. )
  1070. const VaporForwardedSlot = createVaporForwardedSlot(
  1071. VdomForwardedSlotWithFallback,
  1072. )
  1073. const App = createTestApp(VaporForwardedSlot, foo, show)
  1074. const root = document.createElement('div')
  1075. createApp(App).use(vaporInteropPlugin).mount(root)
  1076. expect(root.innerHTML).toBe('<span>foo</span>')
  1077. foo.value = 'bar'
  1078. await nextTick()
  1079. expect(root.innerHTML).toBe('<span>bar</span>')
  1080. show.value = false
  1081. await nextTick()
  1082. expect(root.innerHTML).toBe('<div>vdom fallback</div>')
  1083. show.value = true
  1084. await nextTick()
  1085. expect(root.innerHTML).toBe('<span>bar</span>')
  1086. })
  1087. test('vdom slot > vapor forwarded slot (multiple) > vdom forwarded slot > vdom slot', async () => {
  1088. const foo = ref('foo')
  1089. const show = ref(true)
  1090. const VdomSlot = createVdomSlot()
  1091. const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
  1092. const VaporForwardedSlot = createMultipleVaporForwardedSlots(
  1093. VdomForwardedSlot,
  1094. 3,
  1095. )
  1096. const App = createTestApp(VaporForwardedSlot, foo, show)
  1097. const root = document.createElement('div')
  1098. createApp(App).use(vaporInteropPlugin).mount(root)
  1099. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  1100. foo.value = 'bar'
  1101. await nextTick()
  1102. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1103. show.value = false
  1104. await nextTick()
  1105. expect(root.innerHTML).toBe('<div>fallback</div><!--slot--><!--slot-->')
  1106. show.value = true
  1107. await nextTick()
  1108. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1109. })
  1110. test('vdom slot > vapor forwarded slot (multiple) > vdom forwarded slot(with fallback) > vdom slot', async () => {
  1111. const foo = ref('foo')
  1112. const show = ref(true)
  1113. const VdomSlot = createVdomSlot()
  1114. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1115. VdomSlot,
  1116. 'vdom fallback',
  1117. )
  1118. const VaporForwardedSlot = createMultipleVaporForwardedSlots(
  1119. VdomForwardedSlotWithFallback,
  1120. 3,
  1121. )
  1122. const App = createTestApp(VaporForwardedSlot, foo, show)
  1123. const root = document.createElement('div')
  1124. createApp(App).use(vaporInteropPlugin).mount(root)
  1125. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  1126. foo.value = 'bar'
  1127. await nextTick()
  1128. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1129. show.value = false
  1130. await nextTick()
  1131. expect(root.innerHTML).toBe(
  1132. '<div>vdom fallback</div><!--slot--><!--slot-->',
  1133. )
  1134. show.value = true
  1135. await nextTick()
  1136. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1137. })
  1138. test('vdom slot > vdom forwarded slot > vapor slot', async () => {
  1139. const foo = ref('foo')
  1140. const show = ref(true)
  1141. const VaporSlot = createVaporSlot()
  1142. const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
  1143. const App = createTestApp(VdomForwardedSlot, foo, show)
  1144. const root = document.createElement('div')
  1145. createApp(App).use(vaporInteropPlugin).mount(root)
  1146. expect(root.innerHTML).toBe('<span>foo</span>')
  1147. foo.value = 'bar'
  1148. await nextTick()
  1149. expect(root.innerHTML).toBe('<span>bar</span>')
  1150. show.value = false
  1151. await nextTick()
  1152. expect(root.innerHTML).toBe('<div>fallback</div>')
  1153. show.value = true
  1154. await nextTick()
  1155. expect(root.innerHTML).toBe('<span>bar</span>')
  1156. })
  1157. test('vdom slot > vdom forwarded slot > vapor forwarded slot > vapor slot', async () => {
  1158. const foo = ref('foo')
  1159. const show = ref(true)
  1160. const VaporSlot = createVaporSlot()
  1161. const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
  1162. const VdomForwardedSlot = createVdomForwardedSlot(VaporForwardedSlot)
  1163. const App = createTestApp(VdomForwardedSlot, foo, show)
  1164. const root = document.createElement('div')
  1165. createApp(App).use(vaporInteropPlugin).mount(root)
  1166. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1167. foo.value = 'bar'
  1168. await nextTick()
  1169. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1170. show.value = false
  1171. await nextTick()
  1172. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  1173. show.value = true
  1174. await nextTick()
  1175. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1176. })
  1177. test('vdom slot > vdom forwarded slot (multiple) > vapor forwarded slot > vdom slot', async () => {
  1178. const foo = ref('foo')
  1179. const show = ref(true)
  1180. const VaporSlot = createVaporSlot()
  1181. const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
  1182. const VdomForwardedSlot = createMultipleVdomForwardedSlots(
  1183. VaporForwardedSlot,
  1184. 3,
  1185. )
  1186. const App = createTestApp(VdomForwardedSlot, foo, show)
  1187. const root = document.createElement('div')
  1188. createApp(App).use(vaporInteropPlugin).mount(root)
  1189. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1190. foo.value = 'bar'
  1191. await nextTick()
  1192. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1193. show.value = false
  1194. await nextTick()
  1195. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  1196. show.value = true
  1197. await nextTick()
  1198. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1199. })
  1200. test('vdom slot > vdom forwarded slot (multiple) > vapor forwarded slot(with fallback) > vdom slot', async () => {
  1201. const foo = ref('foo')
  1202. const show = ref(true)
  1203. const VaporSlot = createVaporSlot()
  1204. const VaporForwardedSlot = createVaporForwardedSlot(
  1205. VaporSlot,
  1206. 'vapor fallback',
  1207. )
  1208. const VdomForwardedSlot = createMultipleVdomForwardedSlots(
  1209. VaporForwardedSlot,
  1210. 3,
  1211. )
  1212. const App = createTestApp(VdomForwardedSlot, foo, show)
  1213. const root = document.createElement('div')
  1214. createApp(App).use(vaporInteropPlugin).mount(root)
  1215. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1216. foo.value = 'bar'
  1217. await nextTick()
  1218. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1219. show.value = false
  1220. await nextTick()
  1221. expect(root.innerHTML).toBe('<div>vapor fallback</div><!--slot-->')
  1222. show.value = true
  1223. await nextTick()
  1224. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1225. })
  1226. test('vdom slot > vapor forwarded slot > vapor forwarded slot > vdom slot', async () => {
  1227. const foo = ref('foo')
  1228. const show = ref(true)
  1229. const VdomSlot = createVdomSlot()
  1230. const VaporForwardedSlot1 = createMultipleVaporForwardedSlots(
  1231. VdomSlot,
  1232. 2,
  1233. )
  1234. const App = createTestApp(VaporForwardedSlot1, foo, show)
  1235. const root = document.createElement('div')
  1236. createApp(App).use(vaporInteropPlugin).mount(root)
  1237. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1238. foo.value = 'bar'
  1239. await nextTick()
  1240. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1241. show.value = false
  1242. await nextTick()
  1243. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  1244. show.value = true
  1245. await nextTick()
  1246. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1247. })
  1248. test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot > vdom slot', async () => {
  1249. const foo = ref('foo')
  1250. const show = ref(true)
  1251. const VdomSlot = createVdomSlot()
  1252. const VaporForwardedSlot2 = createVaporForwardedSlot(VdomSlot)
  1253. const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
  1254. VaporForwardedSlot2,
  1255. 'vapor1 fallback',
  1256. )
  1257. const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
  1258. const root = document.createElement('div')
  1259. createApp(App).use(vaporInteropPlugin).mount(root)
  1260. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1261. foo.value = 'bar'
  1262. await nextTick()
  1263. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1264. show.value = false
  1265. await nextTick()
  1266. expect(root.innerHTML).toBe('<div>vapor1 fallback</div><!--slot-->')
  1267. show.value = true
  1268. await nextTick()
  1269. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1270. })
  1271. test('vdom slot > vapor forwarded slot > vapor forwarded slot(with fallback) > vdom slot', async () => {
  1272. const foo = ref('foo')
  1273. const show = ref(true)
  1274. const VdomSlot = createVdomSlot()
  1275. const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
  1276. VdomSlot,
  1277. 'vapor2 fallback',
  1278. )
  1279. const VaporForwardedSlot1 = createVaporForwardedSlot(
  1280. VaporForwardedSlot2WithFallback,
  1281. )
  1282. const App = createTestApp(VaporForwardedSlot1, foo, show)
  1283. const root = document.createElement('div')
  1284. createApp(App).use(vaporInteropPlugin).mount(root)
  1285. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1286. foo.value = 'bar'
  1287. await nextTick()
  1288. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1289. show.value = false
  1290. await nextTick()
  1291. expect(root.innerHTML).toBe('<div>vapor2 fallback</div><!--slot-->')
  1292. show.value = true
  1293. await nextTick()
  1294. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1295. })
  1296. test('vdom slot > vapor forwarded slot > vapor forwarded slot > vapor slot', async () => {
  1297. const foo = ref('foo')
  1298. const show = ref(true)
  1299. const VaporSlot = createVaporSlot()
  1300. const VaporForwardedSlot2 = createVaporForwardedSlot(VaporSlot)
  1301. const VaporForwardedSlot1 =
  1302. createVaporForwardedSlot(VaporForwardedSlot2)
  1303. const App = createTestApp(VaporForwardedSlot1, foo, show)
  1304. const root = document.createElement('div')
  1305. createApp(App).use(vaporInteropPlugin).mount(root)
  1306. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  1307. foo.value = 'bar'
  1308. await nextTick()
  1309. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1310. show.value = false
  1311. await nextTick()
  1312. expect(root.innerHTML).toBe('<div>fallback</div><!--slot--><!--slot-->')
  1313. show.value = true
  1314. await nextTick()
  1315. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1316. })
  1317. test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot(with fallback) > vdom slot', async () => {
  1318. const foo = ref('foo')
  1319. const show = ref(true)
  1320. const VdomSlot = createVdomSlot()
  1321. const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
  1322. VdomSlot,
  1323. 'vapor2 fallback',
  1324. )
  1325. const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
  1326. VaporForwardedSlot2WithFallback,
  1327. 'vapor1 fallback',
  1328. )
  1329. const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
  1330. const root = document.createElement('div')
  1331. createApp(App).use(vaporInteropPlugin).mount(root)
  1332. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1333. foo.value = 'bar'
  1334. await nextTick()
  1335. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1336. show.value = false
  1337. await nextTick()
  1338. expect(root.innerHTML).toBe('<div>vapor1 fallback</div><!--slot-->')
  1339. show.value = true
  1340. await nextTick()
  1341. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1342. })
  1343. test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot(with fallback) > vapor slot', async () => {
  1344. const foo = ref('foo')
  1345. const show = ref(true)
  1346. const VaporSlot = createVaporSlot()
  1347. const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
  1348. VaporSlot,
  1349. 'vapor2 fallback',
  1350. )
  1351. const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
  1352. VaporForwardedSlot2WithFallback,
  1353. 'vapor1 fallback',
  1354. )
  1355. const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
  1356. const root = document.createElement('div')
  1357. createApp(App).use(vaporInteropPlugin).mount(root)
  1358. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  1359. foo.value = 'bar'
  1360. await nextTick()
  1361. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1362. show.value = false
  1363. await nextTick()
  1364. expect(root.innerHTML).toBe(
  1365. '<div>vapor1 fallback</div><!--slot--><!--slot-->',
  1366. )
  1367. show.value = true
  1368. await nextTick()
  1369. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1370. })
  1371. test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) > vapor slot', async () => {
  1372. const foo = ref('foo')
  1373. const show = ref(true)
  1374. const VaporSlot = createVaporSlot()
  1375. const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
  1376. VaporSlot,
  1377. 'vdom2 fallback',
  1378. )
  1379. const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
  1380. VdomForwardedSlot2WithFallback,
  1381. 'vdom1 fallback',
  1382. )
  1383. const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
  1384. const root = document.createElement('div')
  1385. createApp(App).use(vaporInteropPlugin).mount(root)
  1386. expect(root.innerHTML).toBe('<span>foo</span>')
  1387. foo.value = 'bar'
  1388. await nextTick()
  1389. expect(root.innerHTML).toBe('<span>bar</span>')
  1390. show.value = false
  1391. await nextTick()
  1392. expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
  1393. show.value = true
  1394. await nextTick()
  1395. expect(root.innerHTML).toBe('<span>bar</span>')
  1396. })
  1397. test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) > vdom slot', async () => {
  1398. const foo = ref('foo')
  1399. const show = ref(true)
  1400. const VdomSlot = createVdomSlot()
  1401. const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
  1402. VdomSlot,
  1403. 'vdom2 fallback',
  1404. )
  1405. const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
  1406. VdomForwardedSlot2WithFallback,
  1407. 'vdom1 fallback',
  1408. )
  1409. const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
  1410. const root = document.createElement('div')
  1411. createApp(App).use(vaporInteropPlugin).mount(root)
  1412. expect(root.innerHTML).toBe('<span>foo</span>')
  1413. foo.value = 'bar'
  1414. await nextTick()
  1415. expect(root.innerHTML).toBe('<span>bar</span>')
  1416. show.value = false
  1417. await nextTick()
  1418. expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
  1419. show.value = true
  1420. await nextTick()
  1421. expect(root.innerHTML).toBe('<span>bar</span>')
  1422. })
  1423. test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) (multiple) > vapor slot', async () => {
  1424. const foo = ref('foo')
  1425. const show = ref(true)
  1426. const VaporSlot = createVaporSlot()
  1427. const VdomForwardedSlot3WithFallback = createVdomForwardedSlot(
  1428. VaporSlot,
  1429. 'vdom3 fallback',
  1430. )
  1431. const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
  1432. VdomForwardedSlot3WithFallback,
  1433. 'vdom2 fallback',
  1434. )
  1435. const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
  1436. VdomForwardedSlot2WithFallback,
  1437. 'vdom1 fallback',
  1438. )
  1439. const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
  1440. const root = document.createElement('div')
  1441. createApp(App).use(vaporInteropPlugin).mount(root)
  1442. expect(root.innerHTML).toBe('<span>foo</span>')
  1443. foo.value = 'bar'
  1444. await nextTick()
  1445. expect(root.innerHTML).toBe('<span>bar</span>')
  1446. show.value = false
  1447. await nextTick()
  1448. expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
  1449. show.value = true
  1450. await nextTick()
  1451. expect(root.innerHTML).toBe('<span>bar</span>')
  1452. })
  1453. })
  1454. })
  1455. describe('forwarded slot', () => {
  1456. test('should work', async () => {
  1457. const Child = defineVaporComponent({
  1458. setup() {
  1459. return createSlot('foo', null)
  1460. },
  1461. })
  1462. const Parent = defineVaporComponent({
  1463. setup() {
  1464. const createForwardedSlot = forwardedSlotCreator()
  1465. const n2 = createComponent(
  1466. Child,
  1467. null,
  1468. {
  1469. foo: () => {
  1470. return createForwardedSlot('foo', null)
  1471. },
  1472. },
  1473. true,
  1474. )
  1475. return n2
  1476. },
  1477. })
  1478. const foo = ref('foo')
  1479. const { host } = define({
  1480. setup() {
  1481. const n2 = createComponent(
  1482. Parent,
  1483. null,
  1484. {
  1485. foo: () => {
  1486. const n0 = template(' ')() as any
  1487. renderEffect(() => setText(n0, foo.value))
  1488. return n0
  1489. },
  1490. },
  1491. true,
  1492. )
  1493. return n2
  1494. },
  1495. }).render()
  1496. expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->')
  1497. foo.value = 'bar'
  1498. await nextTick()
  1499. expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
  1500. })
  1501. test('mixed with non-forwarded slot', async () => {
  1502. const Child = defineVaporComponent({
  1503. setup() {
  1504. return [createSlot('foo', null)]
  1505. },
  1506. })
  1507. const Parent = defineVaporComponent({
  1508. setup() {
  1509. const createForwardedSlot = forwardedSlotCreator()
  1510. const n2 = createComponent(Child, null, {
  1511. foo: () => {
  1512. const n0 = createForwardedSlot('foo', null)
  1513. return n0
  1514. },
  1515. })
  1516. const n3 = createSlot('default', null)
  1517. return [n2, n3]
  1518. },
  1519. })
  1520. const foo = ref('foo')
  1521. const { host } = define({
  1522. setup() {
  1523. const n2 = createComponent(
  1524. Parent,
  1525. null,
  1526. {
  1527. foo: () => {
  1528. const n0 = template(' ')() as any
  1529. renderEffect(() => setText(n0, foo.value))
  1530. return n0
  1531. },
  1532. default: () => {
  1533. const n3 = template(' ')() as any
  1534. renderEffect(() => setText(n3, foo.value))
  1535. return n3
  1536. },
  1537. },
  1538. true,
  1539. )
  1540. return n2
  1541. },
  1542. }).render()
  1543. expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->foo<!--slot-->')
  1544. foo.value = 'bar'
  1545. await nextTick()
  1546. expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->bar<!--slot-->')
  1547. })
  1548. describe('vdom interop', () => {
  1549. const createVaporSlot = (fallbackText = 'fallback') => {
  1550. return defineVaporComponent({
  1551. setup() {
  1552. const n0 = createSlot('foo', null, () => {
  1553. const n2 = template(`<div>${fallbackText}</div>`)()
  1554. return n2
  1555. })
  1556. return n0
  1557. },
  1558. })
  1559. }
  1560. const createVdomSlot = (fallbackText = 'fallback') => {
  1561. return {
  1562. render(this: any) {
  1563. return renderSlot(this.$slots, 'foo', {}, () => [
  1564. h('div', fallbackText),
  1565. ])
  1566. },
  1567. }
  1568. }
  1569. const createVaporForwardedSlot = (
  1570. targetComponent: any,
  1571. fallbackText?: string,
  1572. ) => {
  1573. return defineVaporComponent({
  1574. setup() {
  1575. const createForwardedSlot = forwardedSlotCreator()
  1576. const n2 = createComponent(
  1577. targetComponent,
  1578. null,
  1579. {
  1580. foo: () => {
  1581. return fallbackText
  1582. ? createForwardedSlot('foo', null, () => {
  1583. const n2 = template(`<div>${fallbackText}</div>`)()
  1584. return n2
  1585. })
  1586. : createForwardedSlot('foo', null)
  1587. },
  1588. },
  1589. true,
  1590. )
  1591. return n2
  1592. },
  1593. })
  1594. }
  1595. const createVdomForwardedSlot = (
  1596. targetComponent: any,
  1597. fallbackText?: string,
  1598. ) => {
  1599. return {
  1600. render(this: any) {
  1601. return h(targetComponent, null, {
  1602. foo: () => [
  1603. fallbackText
  1604. ? renderSlot(this.$slots, 'foo', {}, () => [
  1605. h('div', fallbackText),
  1606. ])
  1607. : renderSlot(this.$slots, 'foo'),
  1608. ],
  1609. _: 3 /* FORWARDED */,
  1610. })
  1611. },
  1612. }
  1613. }
  1614. const createMultipleVaporForwardedSlots = (
  1615. targetComponent: any,
  1616. count: number,
  1617. ) => {
  1618. let current = targetComponent
  1619. for (let i = 0; i < count; i++) {
  1620. current = createVaporForwardedSlot(current)
  1621. }
  1622. return current
  1623. }
  1624. const createMultipleVdomForwardedSlots = (
  1625. targetComponent: any,
  1626. count: number,
  1627. ) => {
  1628. let current = targetComponent
  1629. for (let i = 0; i < count; i++) {
  1630. current = createVdomForwardedSlot(current)
  1631. }
  1632. return current
  1633. }
  1634. const createTestApp = (
  1635. rootComponent: any,
  1636. foo: Ref<string>,
  1637. show: Ref<Boolean>,
  1638. ) => {
  1639. return {
  1640. setup() {
  1641. return () =>
  1642. h(
  1643. rootComponent,
  1644. null,
  1645. createSlots({ _: 2 /* DYNAMIC */ } as any, [
  1646. show.value
  1647. ? {
  1648. name: 'foo',
  1649. fn: () => [h('span', foo.value)],
  1650. key: '0',
  1651. }
  1652. : undefined,
  1653. ]),
  1654. )
  1655. },
  1656. }
  1657. }
  1658. const createEmptyTestApp = (rootComponent: any) => {
  1659. return {
  1660. setup() {
  1661. return () => h(rootComponent)
  1662. },
  1663. }
  1664. }
  1665. test('vdom slot > vapor forwarded slot > vapor slot', async () => {
  1666. const foo = ref('foo')
  1667. const show = ref(true)
  1668. const VaporSlot = createVaporSlot()
  1669. const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
  1670. const App = createTestApp(VaporForwardedSlot, foo, show)
  1671. const root = document.createElement('div')
  1672. createApp(App).use(vaporInteropPlugin).mount(root)
  1673. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1674. foo.value = 'bar'
  1675. await nextTick()
  1676. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1677. show.value = false
  1678. await nextTick()
  1679. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  1680. })
  1681. test('vdom slot > vapor forwarded slot(with fallback) > vapor slot', async () => {
  1682. const foo = ref('foo')
  1683. const show = ref(true)
  1684. const VaporSlot = createVaporSlot()
  1685. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  1686. VaporSlot,
  1687. 'forwarded fallback',
  1688. )
  1689. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  1690. const root = document.createElement('div')
  1691. createApp(App).use(vaporInteropPlugin).mount(root)
  1692. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1693. foo.value = 'bar'
  1694. await nextTick()
  1695. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1696. show.value = false
  1697. await nextTick()
  1698. expect(root.innerHTML).toBe('<div>forwarded fallback</div><!--slot-->')
  1699. })
  1700. test('vdom slot > vapor forwarded slot > vdom slot', async () => {
  1701. const foo = ref('foo')
  1702. const show = ref(true)
  1703. const VdomSlot = createVdomSlot()
  1704. const VaporForwardedSlot = createVaporForwardedSlot(VdomSlot)
  1705. const App = createTestApp(VaporForwardedSlot, foo, show)
  1706. const root = document.createElement('div')
  1707. createApp(App).use(vaporInteropPlugin).mount(root)
  1708. expect(root.innerHTML).toBe('<span>foo</span>')
  1709. foo.value = 'bar'
  1710. await nextTick()
  1711. expect(root.innerHTML).toBe('<span>bar</span>')
  1712. show.value = false
  1713. await nextTick()
  1714. expect(root.innerHTML).toBe('<div>fallback</div>')
  1715. show.value = true
  1716. await nextTick()
  1717. expect(root.innerHTML).toBe('<span>bar</span>')
  1718. })
  1719. test('vdom slot > vapor forwarded slot(with fallback) > vdom slot', async () => {
  1720. const foo = ref('foo')
  1721. const show = ref(true)
  1722. const VdomSlot = createVdomSlot()
  1723. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  1724. VdomSlot,
  1725. 'forwarded fallback',
  1726. )
  1727. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  1728. const root = document.createElement('div')
  1729. createApp(App).use(vaporInteropPlugin).mount(root)
  1730. expect(root.innerHTML).toBe('<span>foo</span>')
  1731. foo.value = 'bar'
  1732. await nextTick()
  1733. expect(root.innerHTML).toBe('<span>bar</span>')
  1734. show.value = false
  1735. await nextTick()
  1736. expect(root.innerHTML).toBe('<div>forwarded fallback</div>')
  1737. })
  1738. test('vdom slot > vapor forwarded slot > vdom forwarded slot > vapor slot', async () => {
  1739. const foo = ref('foo')
  1740. const show = ref(true)
  1741. const VaporSlot = createVaporSlot()
  1742. const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
  1743. const VaporForwardedSlot = createVaporForwardedSlot(VdomForwardedSlot)
  1744. const App = createTestApp(VaporForwardedSlot, foo, show)
  1745. const root = document.createElement('div')
  1746. createApp(App).use(vaporInteropPlugin).mount(root)
  1747. expect(root.innerHTML).toBe('<span>foo</span>')
  1748. foo.value = 'bar'
  1749. await nextTick()
  1750. expect(root.innerHTML).toBe('<span>bar</span>')
  1751. show.value = false
  1752. await nextTick()
  1753. expect(root.innerHTML).toBe('<div>fallback</div>')
  1754. show.value = true
  1755. await nextTick()
  1756. expect(root.innerHTML).toBe('<span>bar</span>')
  1757. })
  1758. test('vdom slot > vapor forwarded slot(with fallback) > vdom forwarded slot > vapor slot', async () => {
  1759. const foo = ref('foo')
  1760. const show = ref(true)
  1761. const VaporSlot = createVaporSlot()
  1762. const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
  1763. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  1764. VdomForwardedSlot,
  1765. 'forwarded fallback',
  1766. )
  1767. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  1768. const root = document.createElement('div')
  1769. createApp(App).use(vaporInteropPlugin).mount(root)
  1770. expect(root.innerHTML).toBe('<span>foo</span>')
  1771. foo.value = 'bar'
  1772. await nextTick()
  1773. expect(root.innerHTML).toBe('<span>bar</span>')
  1774. show.value = false
  1775. await nextTick()
  1776. expect(root.innerHTML).toBe('<div>forwarded fallback</div>')
  1777. show.value = true
  1778. await nextTick()
  1779. expect(root.innerHTML).toBe('<span>bar</span>')
  1780. })
  1781. test('vdom slot > vapor forwarded slot > vdom forwarded slot(with fallback) > vapor slot', async () => {
  1782. const foo = ref('foo')
  1783. const show = ref(true)
  1784. const VaporSlot = createVaporSlot()
  1785. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1786. VaporSlot,
  1787. 'vdom fallback',
  1788. )
  1789. const VaporForwardedSlot = createVaporForwardedSlot(
  1790. VdomForwardedSlotWithFallback,
  1791. )
  1792. const App = createTestApp(VaporForwardedSlot, foo, show)
  1793. const root = document.createElement('div')
  1794. createApp(App).use(vaporInteropPlugin).mount(root)
  1795. expect(root.innerHTML).toBe('<span>foo</span>')
  1796. foo.value = 'bar'
  1797. await nextTick()
  1798. expect(root.innerHTML).toBe('<span>bar</span>')
  1799. show.value = false
  1800. await nextTick()
  1801. expect(root.innerHTML).toBe('<div>vdom fallback</div>')
  1802. show.value = true
  1803. await nextTick()
  1804. expect(root.innerHTML).toBe('<span>bar</span>')
  1805. })
  1806. test('vdom slot(empty) > vapor forwarded slot > vdom forwarded slot(with fallback) > vapor slot', async () => {
  1807. const VaporSlot = createVaporSlot()
  1808. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1809. VaporSlot,
  1810. 'vdom fallback',
  1811. )
  1812. const VaporForwardedSlot = createVaporForwardedSlot(
  1813. VdomForwardedSlotWithFallback,
  1814. )
  1815. const App = createEmptyTestApp(VaporForwardedSlot)
  1816. const root = document.createElement('div')
  1817. createApp(App).use(vaporInteropPlugin).mount(root)
  1818. expect(root.innerHTML).toBe('<div>vdom fallback</div>')
  1819. })
  1820. test('vdom slot > vapor forwarded slot > vdom forwarded slot > vdom slot', async () => {
  1821. const foo = ref('foo')
  1822. const show = ref(true)
  1823. const VdomSlot = createVdomSlot()
  1824. const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
  1825. const VaporForwardedSlot = createVaporForwardedSlot(VdomForwardedSlot)
  1826. const App = createTestApp(VaporForwardedSlot, foo, show)
  1827. const root = document.createElement('div')
  1828. createApp(App).use(vaporInteropPlugin).mount(root)
  1829. expect(root.innerHTML).toBe('<span>foo</span>')
  1830. foo.value = 'bar'
  1831. await nextTick()
  1832. expect(root.innerHTML).toBe('<span>bar</span>')
  1833. show.value = false
  1834. await nextTick()
  1835. expect(root.innerHTML).toBe('<div>fallback</div>')
  1836. show.value = true
  1837. await nextTick()
  1838. expect(root.innerHTML).toBe('<span>bar</span>')
  1839. })
  1840. test('vdom slot > vapor forwarded slot(with fallback) > vdom forwarded slot > vdom slot', async () => {
  1841. const foo = ref('foo')
  1842. const show = ref(true)
  1843. const VdomSlot = createVdomSlot()
  1844. const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
  1845. const VaporForwardedSlotWithFallback = createVaporForwardedSlot(
  1846. VdomForwardedSlot,
  1847. 'vapor fallback',
  1848. )
  1849. const App = createTestApp(VaporForwardedSlotWithFallback, foo, show)
  1850. const root = document.createElement('div')
  1851. createApp(App).use(vaporInteropPlugin).mount(root)
  1852. expect(root.innerHTML).toBe('<span>foo</span>')
  1853. foo.value = 'bar'
  1854. await nextTick()
  1855. expect(root.innerHTML).toBe('<span>bar</span>')
  1856. show.value = false
  1857. await nextTick()
  1858. expect(root.innerHTML).toBe('<div>vapor fallback</div>')
  1859. show.value = true
  1860. await nextTick()
  1861. expect(root.innerHTML).toBe('<span>bar</span>')
  1862. })
  1863. test('vdom slot > vapor forwarded slot > vdom forwarded slot(with fallback) > vdom slot', async () => {
  1864. const foo = ref('foo')
  1865. const show = ref(true)
  1866. const VdomSlot = createVdomSlot()
  1867. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1868. VdomSlot,
  1869. 'vdom fallback',
  1870. )
  1871. const VaporForwardedSlot = createVaporForwardedSlot(
  1872. VdomForwardedSlotWithFallback,
  1873. )
  1874. const App = createTestApp(VaporForwardedSlot, foo, show)
  1875. const root = document.createElement('div')
  1876. createApp(App).use(vaporInteropPlugin).mount(root)
  1877. expect(root.innerHTML).toBe('<span>foo</span>')
  1878. foo.value = 'bar'
  1879. await nextTick()
  1880. expect(root.innerHTML).toBe('<span>bar</span>')
  1881. show.value = false
  1882. await nextTick()
  1883. expect(root.innerHTML).toBe('<div>vdom fallback</div>')
  1884. show.value = true
  1885. await nextTick()
  1886. expect(root.innerHTML).toBe('<span>bar</span>')
  1887. })
  1888. test('vdom slot > vapor forwarded slot (multiple) > vdom forwarded slot > vdom slot', async () => {
  1889. const foo = ref('foo')
  1890. const show = ref(true)
  1891. const VdomSlot = createVdomSlot()
  1892. const VdomForwardedSlot = createVdomForwardedSlot(VdomSlot)
  1893. const VaporForwardedSlot = createMultipleVaporForwardedSlots(
  1894. VdomForwardedSlot,
  1895. 3,
  1896. )
  1897. const App = createTestApp(VaporForwardedSlot, foo, show)
  1898. const root = document.createElement('div')
  1899. createApp(App).use(vaporInteropPlugin).mount(root)
  1900. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  1901. foo.value = 'bar'
  1902. await nextTick()
  1903. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1904. show.value = false
  1905. await nextTick()
  1906. expect(root.innerHTML).toBe('<div>fallback</div><!--slot--><!--slot-->')
  1907. show.value = true
  1908. await nextTick()
  1909. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1910. })
  1911. test('vdom slot > vapor forwarded slot (multiple) > vdom forwarded slot(with fallback) > vdom slot', async () => {
  1912. const foo = ref('foo')
  1913. const show = ref(true)
  1914. const VdomSlot = createVdomSlot()
  1915. const VdomForwardedSlotWithFallback = createVdomForwardedSlot(
  1916. VdomSlot,
  1917. 'vdom fallback',
  1918. )
  1919. const VaporForwardedSlot = createMultipleVaporForwardedSlots(
  1920. VdomForwardedSlotWithFallback,
  1921. 3,
  1922. )
  1923. const App = createTestApp(VaporForwardedSlot, foo, show)
  1924. const root = document.createElement('div')
  1925. createApp(App).use(vaporInteropPlugin).mount(root)
  1926. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  1927. foo.value = 'bar'
  1928. await nextTick()
  1929. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1930. show.value = false
  1931. await nextTick()
  1932. expect(root.innerHTML).toBe(
  1933. '<div>vdom fallback</div><!--slot--><!--slot-->',
  1934. )
  1935. show.value = true
  1936. await nextTick()
  1937. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  1938. })
  1939. test('vdom slot > vdom forwarded slot > vapor slot', async () => {
  1940. const foo = ref('foo')
  1941. const show = ref(true)
  1942. const VaporSlot = createVaporSlot()
  1943. const VdomForwardedSlot = createVdomForwardedSlot(VaporSlot)
  1944. const App = createTestApp(VdomForwardedSlot, foo, show)
  1945. const root = document.createElement('div')
  1946. createApp(App).use(vaporInteropPlugin).mount(root)
  1947. expect(root.innerHTML).toBe('<span>foo</span>')
  1948. foo.value = 'bar'
  1949. await nextTick()
  1950. expect(root.innerHTML).toBe('<span>bar</span>')
  1951. show.value = false
  1952. await nextTick()
  1953. expect(root.innerHTML).toBe('<div>fallback</div>')
  1954. show.value = true
  1955. await nextTick()
  1956. expect(root.innerHTML).toBe('<span>bar</span>')
  1957. })
  1958. test('vdom slot > vdom forwarded slot > vapor forwarded slot > vapor slot', async () => {
  1959. const foo = ref('foo')
  1960. const show = ref(true)
  1961. const VaporSlot = createVaporSlot()
  1962. const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
  1963. const VdomForwardedSlot = createVdomForwardedSlot(VaporForwardedSlot)
  1964. const App = createTestApp(VdomForwardedSlot, foo, show)
  1965. const root = document.createElement('div')
  1966. createApp(App).use(vaporInteropPlugin).mount(root)
  1967. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1968. foo.value = 'bar'
  1969. await nextTick()
  1970. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1971. show.value = false
  1972. await nextTick()
  1973. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  1974. show.value = true
  1975. await nextTick()
  1976. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1977. })
  1978. test('vdom slot > vdom forwarded slot (multiple) > vapor forwarded slot > vdom slot', async () => {
  1979. const foo = ref('foo')
  1980. const show = ref(true)
  1981. const VaporSlot = createVaporSlot()
  1982. const VaporForwardedSlot = createVaporForwardedSlot(VaporSlot)
  1983. const VdomForwardedSlot = createMultipleVdomForwardedSlots(
  1984. VaporForwardedSlot,
  1985. 3,
  1986. )
  1987. const App = createTestApp(VdomForwardedSlot, foo, show)
  1988. const root = document.createElement('div')
  1989. createApp(App).use(vaporInteropPlugin).mount(root)
  1990. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  1991. foo.value = 'bar'
  1992. await nextTick()
  1993. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  1994. show.value = false
  1995. await nextTick()
  1996. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  1997. show.value = true
  1998. await nextTick()
  1999. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2000. })
  2001. test('vdom slot > vdom forwarded slot (multiple) > vapor forwarded slot(with fallback) > vdom slot', async () => {
  2002. const foo = ref('foo')
  2003. const show = ref(true)
  2004. const VaporSlot = createVaporSlot()
  2005. const VaporForwardedSlot = createVaporForwardedSlot(
  2006. VaporSlot,
  2007. 'vapor fallback',
  2008. )
  2009. const VdomForwardedSlot = createMultipleVdomForwardedSlots(
  2010. VaporForwardedSlot,
  2011. 3,
  2012. )
  2013. const App = createTestApp(VdomForwardedSlot, foo, show)
  2014. const root = document.createElement('div')
  2015. createApp(App).use(vaporInteropPlugin).mount(root)
  2016. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  2017. foo.value = 'bar'
  2018. await nextTick()
  2019. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2020. show.value = false
  2021. await nextTick()
  2022. expect(root.innerHTML).toBe('<div>vapor fallback</div><!--slot-->')
  2023. show.value = true
  2024. await nextTick()
  2025. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2026. })
  2027. test('vdom slot > vapor forwarded slot > vapor forwarded slot > vdom slot', async () => {
  2028. const foo = ref('foo')
  2029. const show = ref(true)
  2030. const VdomSlot = createVdomSlot()
  2031. const VaporForwardedSlot1 = createMultipleVaporForwardedSlots(
  2032. VdomSlot,
  2033. 2,
  2034. )
  2035. const App = createTestApp(VaporForwardedSlot1, foo, show)
  2036. const root = document.createElement('div')
  2037. createApp(App).use(vaporInteropPlugin).mount(root)
  2038. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  2039. foo.value = 'bar'
  2040. await nextTick()
  2041. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2042. show.value = false
  2043. await nextTick()
  2044. expect(root.innerHTML).toBe('<div>fallback</div><!--slot-->')
  2045. show.value = true
  2046. await nextTick()
  2047. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2048. })
  2049. test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot > vdom slot', async () => {
  2050. const foo = ref('foo')
  2051. const show = ref(true)
  2052. const VdomSlot = createVdomSlot()
  2053. const VaporForwardedSlot2 = createVaporForwardedSlot(VdomSlot)
  2054. const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
  2055. VaporForwardedSlot2,
  2056. 'vapor1 fallback',
  2057. )
  2058. const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
  2059. const root = document.createElement('div')
  2060. createApp(App).use(vaporInteropPlugin).mount(root)
  2061. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  2062. foo.value = 'bar'
  2063. await nextTick()
  2064. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2065. show.value = false
  2066. await nextTick()
  2067. expect(root.innerHTML).toBe('<div>vapor1 fallback</div><!--slot-->')
  2068. show.value = true
  2069. await nextTick()
  2070. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2071. })
  2072. test('vdom slot > vapor forwarded slot > vapor forwarded slot(with fallback) > vdom slot', async () => {
  2073. const foo = ref('foo')
  2074. const show = ref(true)
  2075. const VdomSlot = createVdomSlot()
  2076. const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
  2077. VdomSlot,
  2078. 'vapor2 fallback',
  2079. )
  2080. const VaporForwardedSlot1 = createVaporForwardedSlot(
  2081. VaporForwardedSlot2WithFallback,
  2082. )
  2083. const App = createTestApp(VaporForwardedSlot1, foo, show)
  2084. const root = document.createElement('div')
  2085. createApp(App).use(vaporInteropPlugin).mount(root)
  2086. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  2087. foo.value = 'bar'
  2088. await nextTick()
  2089. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2090. show.value = false
  2091. await nextTick()
  2092. expect(root.innerHTML).toBe('<div>vapor2 fallback</div><!--slot-->')
  2093. show.value = true
  2094. await nextTick()
  2095. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2096. })
  2097. test('vdom slot > vapor forwarded slot > vapor forwarded slot > vapor slot', async () => {
  2098. const foo = ref('foo')
  2099. const show = ref(true)
  2100. const VaporSlot = createVaporSlot()
  2101. const VaporForwardedSlot2 = createVaporForwardedSlot(VaporSlot)
  2102. const VaporForwardedSlot1 =
  2103. createVaporForwardedSlot(VaporForwardedSlot2)
  2104. const App = createTestApp(VaporForwardedSlot1, foo, show)
  2105. const root = document.createElement('div')
  2106. createApp(App).use(vaporInteropPlugin).mount(root)
  2107. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  2108. foo.value = 'bar'
  2109. await nextTick()
  2110. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  2111. show.value = false
  2112. await nextTick()
  2113. expect(root.innerHTML).toBe('<div>fallback</div><!--slot--><!--slot-->')
  2114. show.value = true
  2115. await nextTick()
  2116. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  2117. })
  2118. test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot(with fallback) > vdom slot', async () => {
  2119. const foo = ref('foo')
  2120. const show = ref(true)
  2121. const VdomSlot = createVdomSlot()
  2122. const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
  2123. VdomSlot,
  2124. 'vapor2 fallback',
  2125. )
  2126. const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
  2127. VaporForwardedSlot2WithFallback,
  2128. 'vapor1 fallback',
  2129. )
  2130. const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
  2131. const root = document.createElement('div')
  2132. createApp(App).use(vaporInteropPlugin).mount(root)
  2133. expect(root.innerHTML).toBe('<span>foo</span><!--slot-->')
  2134. foo.value = 'bar'
  2135. await nextTick()
  2136. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2137. show.value = false
  2138. await nextTick()
  2139. expect(root.innerHTML).toBe('<div>vapor1 fallback</div><!--slot-->')
  2140. show.value = true
  2141. await nextTick()
  2142. expect(root.innerHTML).toBe('<span>bar</span><!--slot-->')
  2143. })
  2144. test('vdom slot > vapor forwarded slot(with fallback) > vapor forwarded slot(with fallback) > vapor slot', async () => {
  2145. const foo = ref('foo')
  2146. const show = ref(true)
  2147. const VaporSlot = createVaporSlot()
  2148. const VaporForwardedSlot2WithFallback = createVaporForwardedSlot(
  2149. VaporSlot,
  2150. 'vapor2 fallback',
  2151. )
  2152. const VaporForwardedSlot1WithFallback = createVaporForwardedSlot(
  2153. VaporForwardedSlot2WithFallback,
  2154. 'vapor1 fallback',
  2155. )
  2156. const App = createTestApp(VaporForwardedSlot1WithFallback, foo, show)
  2157. const root = document.createElement('div')
  2158. createApp(App).use(vaporInteropPlugin).mount(root)
  2159. expect(root.innerHTML).toBe('<span>foo</span><!--slot--><!--slot-->')
  2160. foo.value = 'bar'
  2161. await nextTick()
  2162. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  2163. show.value = false
  2164. await nextTick()
  2165. expect(root.innerHTML).toBe(
  2166. '<div>vapor1 fallback</div><!--slot--><!--slot-->',
  2167. )
  2168. show.value = true
  2169. await nextTick()
  2170. expect(root.innerHTML).toBe('<span>bar</span><!--slot--><!--slot-->')
  2171. })
  2172. test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) > vapor slot', async () => {
  2173. const foo = ref('foo')
  2174. const show = ref(true)
  2175. const VaporSlot = createVaporSlot()
  2176. const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
  2177. VaporSlot,
  2178. 'vdom2 fallback',
  2179. )
  2180. const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
  2181. VdomForwardedSlot2WithFallback,
  2182. 'vdom1 fallback',
  2183. )
  2184. const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
  2185. const root = document.createElement('div')
  2186. createApp(App).use(vaporInteropPlugin).mount(root)
  2187. expect(root.innerHTML).toBe('<span>foo</span>')
  2188. foo.value = 'bar'
  2189. await nextTick()
  2190. expect(root.innerHTML).toBe('<span>bar</span>')
  2191. show.value = false
  2192. await nextTick()
  2193. expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
  2194. show.value = true
  2195. await nextTick()
  2196. expect(root.innerHTML).toBe('<span>bar</span>')
  2197. })
  2198. test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) > vdom slot', async () => {
  2199. const foo = ref('foo')
  2200. const show = ref(true)
  2201. const VdomSlot = createVdomSlot()
  2202. const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
  2203. VdomSlot,
  2204. 'vdom2 fallback',
  2205. )
  2206. const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
  2207. VdomForwardedSlot2WithFallback,
  2208. 'vdom1 fallback',
  2209. )
  2210. const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
  2211. const root = document.createElement('div')
  2212. createApp(App).use(vaporInteropPlugin).mount(root)
  2213. expect(root.innerHTML).toBe('<span>foo</span>')
  2214. foo.value = 'bar'
  2215. await nextTick()
  2216. expect(root.innerHTML).toBe('<span>bar</span>')
  2217. show.value = false
  2218. await nextTick()
  2219. expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
  2220. show.value = true
  2221. await nextTick()
  2222. expect(root.innerHTML).toBe('<span>bar</span>')
  2223. })
  2224. test('vdom slot > vdom forwarded slot(with fallback) > vdom forwarded slot(with fallback) (multiple) > vapor slot', async () => {
  2225. const foo = ref('foo')
  2226. const show = ref(true)
  2227. const VaporSlot = createVaporSlot()
  2228. const VdomForwardedSlot3WithFallback = createVdomForwardedSlot(
  2229. VaporSlot,
  2230. 'vdom3 fallback',
  2231. )
  2232. const VdomForwardedSlot2WithFallback = createVdomForwardedSlot(
  2233. VdomForwardedSlot3WithFallback,
  2234. 'vdom2 fallback',
  2235. )
  2236. const VdomForwardedSlot1WithFallback = createVdomForwardedSlot(
  2237. VdomForwardedSlot2WithFallback,
  2238. 'vdom1 fallback',
  2239. )
  2240. const App = createTestApp(VdomForwardedSlot1WithFallback, foo, show)
  2241. const root = document.createElement('div')
  2242. createApp(App).use(vaporInteropPlugin).mount(root)
  2243. expect(root.innerHTML).toBe('<span>foo</span>')
  2244. foo.value = 'bar'
  2245. await nextTick()
  2246. expect(root.innerHTML).toBe('<span>bar</span>')
  2247. show.value = false
  2248. await nextTick()
  2249. expect(root.innerHTML).toBe('<div>vdom1 fallback</div>')
  2250. show.value = true
  2251. await nextTick()
  2252. expect(root.innerHTML).toBe('<span>bar</span>')
  2253. })
  2254. })
  2255. test('consecutive slots with insertion state', async () => {
  2256. const { component: Child } = define({
  2257. setup() {
  2258. const n2 = template('<div><div>baz</div></div>', true)() as any
  2259. setInsertionState(n2, 0)
  2260. createSlot('default', null)
  2261. setInsertionState(n2, 0)
  2262. createSlot('foo', null)
  2263. return n2
  2264. },
  2265. })
  2266. const { html } = define({
  2267. setup() {
  2268. return createComponent(Child, null, {
  2269. default: () => template('default')(),
  2270. foo: () => template('foo')(),
  2271. })
  2272. },
  2273. }).render()
  2274. expect(html()).toBe(
  2275. `<div>` +
  2276. `default<!--slot-->` +
  2277. `foo<!--slot-->` +
  2278. `<div>baz</div>` +
  2279. `</div>`,
  2280. )
  2281. })
  2282. })
  2283. })