@@ -374,37 +374,40 @@ describe('uiCalendar', function () {
374
374
scope . $apply ( ) ;
375
375
} ) ;
376
376
377
- it ( 'should make sure that all config functions are called in an angular context' , inject ( function ( $timeout , $rootScope ) {
378
- var functionCount = 0 ;
379
- scope . uiConfig = {
380
- calendar :{
381
- height : 200 ,
382
- weekends : false ,
383
- defaultView : 'month' ,
384
- dayClick : function ( ) { } ,
385
- eventClick : function ( ) { } ,
386
- eventDrop : function ( ) { } ,
387
- eventResize : function ( ) { } ,
388
- eventMouseover : function ( ) { }
389
- }
390
- } ;
377
+ it ( 'should make sure that all config functions are called in an angular context' , inject ( function ( $rootScope ) {
378
+ scope . uiConfig = {
379
+ calendar :{
380
+ height : 200 ,
381
+ weekends : false ,
382
+ defaultView : 'month'
383
+ }
384
+ } ;
391
385
392
- spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
386
+ var keys = [ 'dayClick' , 'eventClick' , 'eventDrop' , 'eventResize' , 'eventMouseover' ] ;
387
+ angular . forEach ( keys , function ( key ) {
388
+ scope . uiConfig . calendar [ key ] = jasmine . createSpy ( ) . andReturn ( key ) ;
389
+ } ) ;
393
390
394
- angular . forEach ( scope . uiConfig . calendar , function ( value , key ) {
395
- if ( typeof value === 'function' ) {
396
- functionCount ++ ;
397
- spyOn ( scope . uiConfig . calendar , key ) . andCallThrough ( ) ;
391
+ var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
398
392
399
- var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
393
+ spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
400
394
401
- fullCalendarConfig [ key ] ( ) ;
402
- $timeout . flush ( ) ;
403
- expect ( $rootScope . $apply . callCount ) . toBe ( functionCount ) ;
404
- expect ( scope . uiConfig . calendar [ key ] ) . toHaveBeenCalled ( ) ;
405
- $rootScope . $apply . isSpy = false ;
406
- }
407
- } ) ;
395
+ angular . forEach ( keys , function ( key ) {
396
+ $rootScope . $apply . reset ( ) ;
397
+
398
+ var fn = fullCalendarConfig [ key ] ;
399
+
400
+ expect ( fn ( ) ) . toBe ( key ) ;
401
+ expect ( $rootScope . $apply . callCount ) . toBe ( 1 ) ;
402
+ expect ( scope . uiConfig . calendar [ key ] . callCount ) . toBe ( 1 ) ;
403
+
404
+ expect ( $rootScope . $apply ( function ( ) {
405
+ expect ( $rootScope . $apply . callCount ) . toBe ( 2 ) ;
406
+ return fn ( ) ;
407
+ } ) ) . toBe ( key ) ;
408
+ expect ( $rootScope . $apply . callCount ) . toBe ( 2 ) ;
409
+ expect ( scope . uiConfig . calendar [ key ] . callCount ) . toBe ( 2 ) ;
410
+ } ) ;
408
411
} ) ) ;
409
412
410
413
it ( 'should check that any function that already has an apply in it does not break the calendar (backwards compatible)' , inject ( function ( $timeout , $rootScope ) {
0 commit comments