1
1
// Note: emits and listener fallthrough is tested in
2
2
// ./rendererAttrsFallthrough.spec.ts.
3
3
4
- import { render , defineComponent , h , nodeOps } from '@vue/runtime-test'
4
+ import {
5
+ render ,
6
+ defineComponent ,
7
+ h ,
8
+ nodeOps ,
9
+ toHandlers
10
+ } from '@vue/runtime-test'
5
11
import { isEmitListener } from '../src/componentEmits'
6
12
7
13
describe ( 'component: emit' , ( ) => {
@@ -28,7 +34,7 @@ describe('component: emit', () => {
28
34
expect ( onBaz ) . toHaveBeenCalled ( )
29
35
} )
30
36
31
- test ( 'trigger camelize event ' , ( ) => {
37
+ test ( 'trigger camelCase handler ' , ( ) => {
32
38
const Foo = defineComponent ( {
33
39
render ( ) { } ,
34
40
created ( ) {
@@ -43,7 +49,52 @@ describe('component: emit', () => {
43
49
} )
44
50
render ( h ( Comp ) , nodeOps . createElement ( 'div' ) )
45
51
46
- expect ( fooSpy ) . toHaveBeenCalled ( )
52
+ expect ( fooSpy ) . toHaveBeenCalledTimes ( 1 )
53
+ } )
54
+
55
+ test ( 'trigger kebab-case handler' , ( ) => {
56
+ const Foo = defineComponent ( {
57
+ render ( ) { } ,
58
+ created ( ) {
59
+ this . $emit ( 'test-event' )
60
+ }
61
+ } )
62
+
63
+ const fooSpy = jest . fn ( )
64
+ const Comp = ( ) =>
65
+ h ( Foo , {
66
+ 'onTest-event' : fooSpy
67
+ } )
68
+ render ( h ( Comp ) , nodeOps . createElement ( 'div' ) )
69
+
70
+ expect ( fooSpy ) . toHaveBeenCalledTimes ( 1 )
71
+ } )
72
+
73
+ // #3527
74
+ test ( 'trigger mixed case handlers' , ( ) => {
75
+ const Foo = defineComponent ( {
76
+ render ( ) { } ,
77
+ created ( ) {
78
+ this . $emit ( 'test-event' )
79
+ this . $emit ( 'testEvent' )
80
+ }
81
+ } )
82
+
83
+ const fooSpy = jest . fn ( )
84
+ const barSpy = jest . fn ( )
85
+ const Comp = ( ) =>
86
+ // simulate v-on="obj" usage
87
+ h (
88
+ Foo ,
89
+ toHandlers ( {
90
+ 'test-event' : fooSpy ,
91
+ testEvent : barSpy
92
+ } )
93
+ )
94
+ render ( h ( Comp ) , nodeOps . createElement ( 'div' ) )
95
+
96
+ expect ( fooSpy ) . toHaveBeenCalledTimes ( 1 )
97
+ expect ( fooSpy ) . toHaveBeenCalledTimes ( 1 )
47
98
} )
48
99
49
100
// for v-model:foo-bar usage in DOM templates
0 commit comments