]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(compiler-vapor): add test for v-if with v-once
authordaiwei <daiwei521@126.com>
Tue, 25 Nov 2025 09:06:32 +0000 (17:06 +0800)
committerdaiwei <daiwei521@126.com>
Tue, 25 Nov 2025 09:06:32 +0000 (17:06 +0800)
packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap
packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

index ea76190cd0a14a51392fa4b499f0b4ab90b736cd..608e4bac51053923a8fa752e47762031c3615ba9 100644 (file)
@@ -293,3 +293,18 @@ export function render(_ctx) {
   return [n0, n6]
 }"
 `;
+
+exports[`compiler: v-if > v-if with v-once 1`] = `
+"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, createIf as _createIf, template as _template } from 'vue';
+const t0 = _template("<div> </div>", true)
+
+export function render(_ctx) {
+  const n0 = _createIf(() => (_ctx.ok), () => {
+    const n2 = t0()
+    const x2 = _txt(n2)
+    _setText(x2, _toDisplayString(_ctx.msg))
+    return n2
+  }, null, true)
+  return n0
+}"
+`;
index 3bd39fc9487a0ed83a219596515f6a632e7f3003..728b3f9c41fdf2b352cc9c9b710138fbe7077bba 100644 (file)
@@ -204,7 +204,14 @@ describe('compiler: v-if', () => {
     expect(ir.block.returns).toEqual([0, 3])
   })
 
-  test.todo('v-if with v-once')
+  test('v-if with v-once', () => {
+    const { code, ir, helpers } = compileWithVIf(
+      `<div v-if="ok" v-once>{{ msg }}</div>`,
+    )
+    expect(code).matchSnapshot()
+    expect(helpers).contains('createIf')
+    expect([...ir.template.keys()]).toEqual(['<div> </div>'])
+  })
 
   test('component v-if', () => {
     const { code, ir, helpers } = compileWithVIf(