]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: v-once as root node (#2)
authorRizumu Ayaka <rizumu@ayaka.moe>
Sat, 25 Nov 2023 09:05:00 +0000 (17:05 +0800)
committerGitHub <noreply@github.com>
Sat, 25 Nov 2023 09:05:00 +0000 (17:05 +0800)
packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap
packages/compiler-vapor/__tests__/compile.test.ts

index bba5cbb222bb9c79c57e135b3ec4760fc98c6e69..43bd84de08f2b824a2911596556894e047eb9da9 100644 (file)
@@ -75,7 +75,21 @@ export function render() {
 "
 `;
 
-exports[`comile > directives > v-once 1`] = `
+exports[`comile > directives > v-once > as root node 1`] = `
+"import { watchEffect } from 'vue';
+import { template, setAttr } from 'vue/vapor';
+const t0 = template(\`<div></div>\`);
+export function render() {
+  const n0 = t0();
+  watchEffect(() => {
+    setAttr(n0, 'id', undefined, foo);
+  });
+  return n0;
+}
+"
+`;
+
+exports[`comile > directives > v-once > basic 1`] = `
 "import { template, children, insert, setText, setAttr } from 'vue/vapor';
 const t0 = template(\`<div> <span></span></div>\`);
 export function render() {
index 80079114657c5a517f60f1c12aa7f21ef426e2f0..2c1eacca5c5198f89f9b550f735dba2fbe0a6a24 100644 (file)
@@ -92,20 +92,28 @@ describe('comile', () => {
       })
     })
 
-    test('v-once', async () => {
-      const code = await compile(
-        `<div v-once>
+    describe('v-once', () => {
+      test('basic', async () => {
+        const code = await compile(
+          `<div v-once>
           {{ msg }}
           <span :class="clz" />
         </div>`,
-        {
-          bindingMetadata: {
-            msg: BindingTypes.SETUP_REF,
-            clz: BindingTypes.SETUP_REF,
+          {
+            bindingMetadata: {
+              msg: BindingTypes.SETUP_REF,
+              clz: BindingTypes.SETUP_REF,
+            },
           },
-        },
-      )
-      expect(code).matchSnapshot()
+        )
+        expect(code).matchSnapshot()
+      })
+
+      test.fails('as root node', async () => {
+        const code = await compile(`<div :id="foo" v-once />`)
+        expect(code).toMatchSnapshot()
+        expect(code).not.contains('watchEffect')
+      })
     })
   })
 })