@@ -14,17 +14,43 @@ describe('element', function () {
14
14
document . body . removeChild ( button ) ;
15
15
} ) ;
16
16
17
- it ( 'should work with addEventListener' , function ( ) {
17
+ it ( 'should work with addEventListener when called with a function listener' , function ( ) {
18
+ var clickEvent = document . createEvent ( 'Event' ) ;
19
+ clickEvent . initEvent ( 'click' , true , true ) ;
20
+
18
21
testZone . run ( function ( ) {
19
- button . addEventListener ( 'click' , function ( ) {
22
+ button . addEventListener ( 'click' , function ( event ) {
20
23
expect ( zone ) . toBeDirectChildOf ( testZone ) ;
24
+ expect ( event ) . toBe ( clickEvent )
21
25
} ) ;
22
26
} ) ;
23
27
24
- button . click ( ) ;
28
+ button . dispatchEvent ( clickEvent ) ;
25
29
} ) ;
26
30
27
- it ( 'should respect removeEventListener' , function ( ) {
31
+ it ( 'should work with addEventListener when called with an EventListener-implementing listener' , function ( ) {
32
+ var eventListener = {
33
+ x : 5 ,
34
+ handleEvent : function ( event ) {
35
+ // Test that context is preserved
36
+ expect ( this . x ) . toBe ( 5 ) ;
37
+
38
+ expect ( event ) . toBe ( clickEvent ) ;
39
+ expect ( zone ) . toBeDirectChildOf ( testZone ) ;
40
+ }
41
+ } ;
42
+
43
+ var clickEvent = document . createEvent ( 'Event' ) ;
44
+ clickEvent . initEvent ( 'click' , true , true ) ;
45
+
46
+ testZone . run ( function ( ) {
47
+ button . addEventListener ( 'click' , eventListener ) ;
48
+ } ) ;
49
+
50
+ button . dispatchEvent ( clickEvent ) ;
51
+ } ) ;
52
+
53
+ it ( 'should respect removeEventListener when called with a function listener' , function ( ) {
28
54
var log = '' ;
29
55
var logFunction = function logFunction ( ) {
30
56
log += 'a' ;
@@ -44,6 +70,20 @@ describe('element', function () {
44
70
expect ( log ) . toEqual ( 'aa' ) ;
45
71
} ) ;
46
72
73
+ it ( 'should respect removeEventListener with an EventListener-implementing listener' , function ( ) {
74
+ var eventListener = {
75
+ x : 5 ,
76
+ handleEvent : jasmine . createSpy ( 'handleEvent' )
77
+ } ;
78
+
79
+ button . addEventListener ( 'click' , eventListener ) ;
80
+ button . removeEventListener ( 'click' , eventListener ) ;
81
+
82
+ button . click ( ) ;
83
+
84
+ expect ( eventListener . handleEvent ) . not . toHaveBeenCalled ( ) ;
85
+ } ) ;
86
+
47
87
48
88
describe ( 'onclick' , function ( ) {
49
89
0 commit comments