]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: test the right branches of code
authorEvan You <yyx990803@gmail.com>
Wed, 25 Sep 2019 02:56:57 +0000 (22:56 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 25 Sep 2019 02:56:57 +0000 (22:56 -0400)
packages/compiler-core/__tests__/transforms/vBind.spec.ts
packages/compiler-core/__tests__/transforms/vOn.spec.ts
packages/compiler-core/src/transforms/vOn.ts

index e804d1a118b7b57d7e26573b4b40cf257e613fc5..016efeedd8a8dae9a59bfdb491fd4e04b18a67c1 100644 (file)
@@ -87,7 +87,7 @@ describe('compiler: transform v-bind', () => {
 
   test('should error if no expression', () => {
     const onError = jest.fn()
-    parseWithVBind(`<div v-bind />`, { onError })
+    parseWithVBind(`<div v-bind:arg />`, { onError })
     expect(onError.mock.calls[0][0]).toMatchObject({
       code: ErrorCodes.X_V_BIND_NO_EXPRESSION,
       loc: {
@@ -97,7 +97,7 @@ describe('compiler: transform v-bind', () => {
         },
         end: {
           line: 1,
-          column: 12
+          column: 16
         }
       }
     })
index 41159d97af3e8dc38a8d46babf589b116b26d523..713b34be59b55d903d687e0d3f1cd8d88fa7bd7a 100644 (file)
@@ -103,9 +103,9 @@ describe('compiler: transform v-bind', () => {
     })
   })
 
-  test('should error if no expression', () => {
+  test('should error if no expression AND no modifier', () => {
     const onError = jest.fn()
-    parseWithVOn(`<div v-on />`, { onError })
+    parseWithVOn(`<div v-on:click />`, { onError })
     expect(onError.mock.calls[0][0]).toMatchObject({
       code: ErrorCodes.X_V_ON_NO_EXPRESSION,
       loc: {
@@ -115,11 +115,17 @@ describe('compiler: transform v-bind', () => {
         },
         end: {
           line: 1,
-          column: 10
+          column: 16
         }
       }
     })
   })
 
+  test('should NOT error if no expression but has modifier', () => {
+    const onError = jest.fn()
+    parseWithVOn(`<div v-on:click.prevent />`, { onError })
+    expect(onError).not.toHaveBeenCalled()
+  })
+
   test.todo('.once modifier')
 })
index db3b51ee4df3882ef472294f34e604a9480538c8..7d88aa7c3c9a09e0d45c9da19453ee710f11a84e 100644 (file)
@@ -7,8 +7,11 @@ import { isSimpleIdentifier } from '../utils'
 // v-on without arg is handled directly in ./element.ts due to it affecting
 // codegen for the entire props object. This transform here is only for v-on
 // *with* args.
-export const transformOn: DirectiveTransform = ({ arg, exp, loc }, context) => {
-  if (!exp) {
+export const transformOn: DirectiveTransform = (
+  { arg, exp, loc, modifiers },
+  context
+) => {
+  if (!exp && !modifiers.length) {
     context.onError(createCompilerError(ErrorCodes.X_V_ON_NO_EXPRESSION, loc))
   }
   const { content, children, isStatic, loc: argLoc } = arg!