File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ import Pub_Sub from './pub_sub.js' ;
2+ let instance = null ;
3+ beforeEach ( ( ) => {
4+ instance = new Pub_Sub ( ) ;
5+ } ) ;
6+ afterEach ( ( ) => {
7+ instance = null ;
8+ } ) ;
9+ describe ( 'Pub_Sub.prototype.on : ' , ( ) => {
10+ test ( 'it can attach diferent event handlers function for one event' , ( ) => {
11+ expect ( instance . _publishers . onSelect . length ) . toBe ( 0 ) ;
12+ instance . on ( 'onSelect' , ( ) => { } ) ;
13+ instance . on ( 'onSelect' , ( ) => { } ) ;
14+ expect ( instance . _publishers . onSelect . length ) . toBe ( 2 ) ;
15+ } ) ;
16+ test ( 'it does not attach an event handler twice' , ( ) => {
17+ expect ( instance . _publishers . onSelect . length ) . toBe ( 0 ) ;
18+ const onSelectHandler = ( ) => { } ;
19+ instance . on ( 'onSelect' , onSelectHandler ) ;
20+ instance . on ( 'onSelect' , onSelectHandler ) ;
21+ expect ( instance . _publishers . onSelect . length ) . toBe ( 1 ) ;
22+ } ) ;
23+ test ( 'it can not attach an event handler for beforeSelect or beforeClose event' , ( ) => {
24+ instance . on ( 'beforeSelect' , ( ) => { } ) ;
25+ instance . on ( 'beforeClose' , ( ) => { } ) ;
26+ expect ( typeof instance . _publishers . beforeSelect ) . toBe ( 'undefined' ) ;
27+ expect ( typeof instance . _publishers . beforeClose ) . toBe ( 'undefined' ) ;
28+ } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments