]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(compiler): test for DirectiveTransform returning needRuntime: Symbol
authorEvan You <yyx990803@gmail.com>
Thu, 10 Oct 2019 22:05:43 +0000 (18:05 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 10 Oct 2019 22:05:43 +0000 (18:05 -0400)
packages/compiler-core/__tests__/transforms/transformElement.spec.ts

index 072d34950f17ef0be977b354897ffda5fc48873c..ae44be6847c989648c05340d5884135a7de94905 100644 (file)
@@ -5,7 +5,8 @@ import {
   MERGE_PROPS,
   RESOLVE_DIRECTIVE,
   APPLY_DIRECTIVES,
-  TO_HANDLERS
+  TO_HANDLERS,
+  helperNameMap
 } from '../../src/runtimeHelpers'
 import {
   CallExpression,
@@ -349,6 +350,29 @@ describe('compiler: element transform', () => {
     ])
   })
 
+  test('directiveTransform with needRuntime: Symbol', () => {
+    const { root, node } = parseWithElementTransform(
+      `<div v-foo:bar="hello" />`,
+      {
+        directiveTransforms: {
+          foo() {
+            return {
+              props: [],
+              needRuntime: CREATE_VNODE
+            }
+          }
+        }
+      }
+    )
+
+    expect(root.helpers).toContain(CREATE_VNODE)
+    expect(root.helpers).not.toContain(RESOLVE_DIRECTIVE)
+    expect(root.directives.length).toBe(0)
+    expect((node as any).arguments[1].elements[0].elements[0]).toBe(
+      `_${helperNameMap[CREATE_VNODE]}`
+    )
+  })
+
   test('runtime directives', () => {
     const { root, node } = parseWithElementTransform(
       `<div v-foo v-bar="x" v-baz:[arg].mod.mad="y" />`