@@ -20,34 +20,48 @@ describe('events', () => {
20
20
var object = null
21
21
22
22
beforeEach ( ( ) => {
23
- object = sinon . stub ( {
23
+ // Note: es6 class instances have non-enumerable prototype properties.
24
+ function FB ( ) { } ;
25
+ FB . prototype = {
26
+ onPrototypeBar ( ) { }
27
+ }
28
+ object = new FB ( )
29
+ Object . assign ( object , {
24
30
onFoo : ( ) => { } ,
25
31
onFooBar : ( ) => { } ,
26
- foo : ( ) => { } ,
27
- bar : ( ) => { }
32
+ foo : ( ) => { }
28
33
} )
34
+
29
35
emitter . bind ( object )
30
36
} )
31
37
32
38
it ( 'should register all "on" methods to events' , ( ) => {
39
+ sinon . spy ( object , 'onFoo' )
33
40
emitter . emit ( 'foo' )
34
41
expect ( object . onFoo ) . to . have . been . called
35
42
43
+ sinon . spy ( object , 'onFooBar' )
36
44
emitter . emit ( 'foo_bar' )
37
45
expect ( object . onFooBar ) . to . have . been . called
38
46
47
+ sinon . spy ( object , 'onPrototypeBar' )
48
+ emitter . emit ( 'prototype_bar' )
49
+ expect ( object . onPrototypeBar ) . to . have . been . called
50
+
51
+ sinon . spy ( object , 'foo' )
39
52
expect ( object . foo ) . not . to . have . been . called
40
- expect ( object . bar ) . not . to . have . been . called
41
53
} )
42
54
43
55
it ( 'should bind methods to the owner object' , ( ) => {
56
+ sinon . spy ( object , 'foo' )
57
+ sinon . spy ( object , 'onFoo' )
58
+ sinon . spy ( object , 'onFooBar' )
44
59
emitter . emit ( 'foo' )
45
60
emitter . emit ( 'foo_bar' )
46
61
47
62
expect ( object . onFoo ) . to . have . always . been . calledOn ( object )
48
63
expect ( object . onFooBar ) . to . have . always . been . calledOn ( object )
49
64
expect ( object . foo ) . not . to . have . been . called
50
- expect ( object . bar ) . not . to . have . been . called
51
65
} )
52
66
} )
53
67
0 commit comments