Browse Source

test: add v-once handling to createIf function

daiwei 4 months ago
parent
commit
55d7507687
1 changed files with 22 additions and 0 deletions
  1. 22 0
      packages/runtime-vapor/__tests__/if.spec.ts

+ 22 - 0
packages/runtime-vapor/__tests__/if.spec.ts

@@ -134,6 +134,28 @@ describe('createIf', () => {
     expect(host.innerHTML).toBe('<!--if-->')
   })
 
+  test('with v-once', async () => {
+    const toggle = ref(false)
+    const { html } = define({
+      setup() {
+        return createIf(
+          () => toggle.value,
+          () => template('<p>foo</p>')(),
+          () => template('<p>bar</p>')(),
+          true,
+        )
+      },
+    }).render()
+
+    expect(html()).toBe('<p>bar</p>')
+
+    toggle.value = true
+    await nextTick()
+    // should not change
+    expect(html()).toBe('<p>bar</p>')
+  })
+
+  // vapor custom directives have no lifecycle hooks.
   test.todo('should work with directive hooks', async () => {
     const calls: string[] = []
     const show1 = ref(true)