componentSlots.spec.ts 82 KB

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