Procházet zdrojové kódy

test: add more tests

daiwei před 10 měsíci
rodič
revize
5ba35e7bc2
1 změnil soubory, kde provedl 25 přidání a 3 odebrání
  1. 25 3
      packages/runtime-vapor/__tests__/hydration.spec.ts

+ 25 - 3
packages/runtime-vapor/__tests__/hydration.spec.ts

@@ -1791,23 +1791,45 @@ describe('Vapor Mode hydration', () => {
 
   describe('for', () => {
     test('basic v-for', async () => {
+      const { container, data } = await testHydration(
+        `<template>
+          <span v-for="item in data" :key="item">{{ item }}</span>
+        </template>`,
+        undefined,
+        ref(['a', 'b', 'c']),
+      )
+      expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
+        `"<span>a</span><span>b</span><span>c</span><!--for-->"`,
+      )
+
+      data.value.push('d')
+      await nextTick()
+      expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
+        `"<span>a</span><span>b</span><span>c</span><span>d</span><!--for-->"`,
+      )
+    })
+
+    test('v-for with insertion parent + sibling component', async () => {
       const { container, data } = await testHydration(
         `<template>
           <div>
             <span v-for="item in data" :key="item">{{ item }}</span>
           </div>
+          <components.Child/>
         </template>`,
-        undefined,
+        {
+          Child: `<template><div>{{data.length}}</div></template>`,
+        },
         ref(['a', 'b', 'c']),
       )
       expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
-        `"<div><span>a</span><span>b</span><span>c</span><!--for--></div>"`,
+        `"<div><span>a</span><span>b</span><span>c</span><!--for--></div><div>3</div>"`,
       )
 
       data.value.push('d')
       await nextTick()
       expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
-        `"<div><span>a</span><span>b</span><span>c</span><span>d</span><!--for--></div>"`,
+        `"<div><span>a</span><span>b</span><span>c</span><span>d</span><!--for--></div><div>4</div>"`,
       )
     })