Skip to content

Commit af58508

Browse files
committed
test: test the right branches of code
1 parent 642a44f commit af58508

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/compiler-core/__tests__/transforms/vBind.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('compiler: transform v-bind', () => {
8787

8888
test('should error if no expression', () => {
8989
const onError = jest.fn()
90-
parseWithVBind(`<div v-bind />`, { onError })
90+
parseWithVBind(`<div v-bind:arg />`, { onError })
9191
expect(onError.mock.calls[0][0]).toMatchObject({
9292
code: ErrorCodes.X_V_BIND_NO_EXPRESSION,
9393
loc: {
@@ -97,7 +97,7 @@ describe('compiler: transform v-bind', () => {
9797
},
9898
end: {
9999
line: 1,
100-
column: 12
100+
column: 16
101101
}
102102
}
103103
})

packages/compiler-core/__tests__/transforms/vOn.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ describe('compiler: transform v-bind', () => {
103103
})
104104
})
105105

106-
test('should error if no expression', () => {
106+
test('should error if no expression AND no modifier', () => {
107107
const onError = jest.fn()
108-
parseWithVOn(`<div v-on />`, { onError })
108+
parseWithVOn(`<div v-on:click />`, { onError })
109109
expect(onError.mock.calls[0][0]).toMatchObject({
110110
code: ErrorCodes.X_V_ON_NO_EXPRESSION,
111111
loc: {
@@ -115,11 +115,17 @@ describe('compiler: transform v-bind', () => {
115115
},
116116
end: {
117117
line: 1,
118-
column: 10
118+
column: 16
119119
}
120120
}
121121
})
122122
})
123123

124+
test('should NOT error if no expression but has modifier', () => {
125+
const onError = jest.fn()
126+
parseWithVOn(`<div v-on:click.prevent />`, { onError })
127+
expect(onError).not.toHaveBeenCalled()
128+
})
129+
124130
test.todo('.once modifier')
125131
})

packages/compiler-core/src/transforms/vOn.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import { isSimpleIdentifier } from '../utils'
77
// v-on without arg is handled directly in ./element.ts due to it affecting
88
// codegen for the entire props object. This transform here is only for v-on
99
// *with* args.
10-
export const transformOn: DirectiveTransform = ({ arg, exp, loc }, context) => {
11-
if (!exp) {
10+
export const transformOn: DirectiveTransform = (
11+
{ arg, exp, loc, modifiers },
12+
context
13+
) => {
14+
if (!exp && !modifiers.length) {
1215
context.onError(createCompilerError(ErrorCodes.X_V_ON_NO_EXPRESSION, loc))
1316
}
1417
const { content, children, isStatic, loc: argLoc } = arg!

0 commit comments

Comments
 (0)