This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,8 @@ function patchEventTargetMethods(obj) {
115
115
116
116
handler [ originalFnKey ] = fn ;
117
117
handler [ boundFnsKey ] = handler [ boundFnsKey ] || { } ;
118
- arguments [ 1 ] = handler [ boundFnsKey ] [ eventType ] = zone . bind ( fn ) ;
118
+ handler [ boundFnsKey ] [ eventType ] = handler [ boundFnsKey ] [ eventType ] || zone . bind ( fn ) ;
119
+ arguments [ 1 ] = handler [ boundFnsKey ] [ eventType ] ;
119
120
}
120
121
return global . zone . addEventListener . apply ( this , arguments ) ;
121
122
} ;
Original file line number Diff line number Diff line change @@ -84,6 +84,32 @@ describe('element', function () {
84
84
expect ( eventListener . handleEvent ) . not . toHaveBeenCalled ( ) ;
85
85
} ) ;
86
86
87
+
88
+ it ( 'should only add a listener once for a given set of arguments' , function ( ) {
89
+ var log = [ ] ;
90
+ var clickEvent = document . createEvent ( 'Event' ) ;
91
+
92
+ function listener ( ) {
93
+ log . push ( 'listener' ) ;
94
+ }
95
+
96
+ clickEvent . initEvent ( 'click' , true , true ) ;
97
+
98
+ button . addEventListener ( 'click' , listener ) ;
99
+ button . addEventListener ( 'click' , listener ) ;
100
+ button . addEventListener ( 'click' , listener ) ;
101
+
102
+ button . dispatchEvent ( clickEvent ) ;
103
+
104
+ button . removeEventListener ( 'click' , listener ) ;
105
+
106
+ button . dispatchEvent ( clickEvent ) ;
107
+
108
+ expect ( log ) . toEqual ( [
109
+ 'listener'
110
+ ] ) ;
111
+ } ) ;
112
+
87
113
it ( 'should correctly handle capturing versus nonCapturing eventListeners' , function ( ) {
88
114
var log = [ ] ;
89
115
var clickEvent = document . createEvent ( 'Event' ) ;
You can’t perform that action at this time.
0 commit comments