فهرست منبع

test(compiler-vapor): add test for v-if with v-once

daiwei 5 ماه پیش
والد
کامیت
a32650abf6

+ 15 - 0
packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap

@@ -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
+}"
+`;

+ 8 - 1
packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

@@ -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(