Ver código fonte

test: v-once as root node (#2)

Rizumu Ayaka 2 anos atrás
pai
commit
9b2a6ffe70

+ 15 - 1
packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap

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

+ 18 - 10
packages/compiler-vapor/__tests__/compile.test.ts

@@ -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')
+      })
     })
   })
 })