@@ -352,37 +352,40 @@ describe('uiCalendar', function () {
352352 scope . $apply ( ) ;
353353 } ) ;
354354
355- it ( 'should make sure that all config functions are called in an angular context' , inject ( function ( $timeout , $rootScope ) {
356- var functionCount = 0 ;
357- scope . uiConfig = {
358- calendar :{
359- height : 200 ,
360- weekends : false ,
361- defaultView : 'month' ,
362- dayClick : function ( ) { } ,
363- eventClick : function ( ) { } ,
364- eventDrop : function ( ) { } ,
365- eventResize : function ( ) { } ,
366- eventMouseover : function ( ) { }
367- }
368- } ;
355+ it ( 'should make sure that all config functions are called in an angular context' , inject ( function ( $rootScope ) {
356+ scope . uiConfig = {
357+ calendar :{
358+ height : 200 ,
359+ weekends : false ,
360+ defaultView : 'month'
361+ }
362+ } ;
369363
370- spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
364+ var keys = [ 'dayClick' , 'eventClick' , 'eventDrop' , 'eventResize' , 'eventMouseover' ] ;
365+ angular . forEach ( keys , function ( key ) {
366+ scope . uiConfig . calendar [ key ] = jasmine . createSpy ( ) . andReturn ( key ) ;
367+ } ) ;
371368
372- angular . forEach ( scope . uiConfig . calendar , function ( value , key ) {
373- if ( typeof value === 'function' ) {
374- functionCount ++ ;
375- spyOn ( scope . uiConfig . calendar , key ) . andCallThrough ( ) ;
369+ var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
376370
377- var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
371+ spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
378372
379- fullCalendarConfig [ key ] ( ) ;
380- $timeout . flush ( ) ;
381- expect ( $rootScope . $apply . callCount ) . toBe ( functionCount ) ;
382- expect ( scope . uiConfig . calendar [ key ] ) . toHaveBeenCalled ( ) ;
383- $rootScope . $apply . isSpy = false ;
384- }
385- } ) ;
373+ angular . forEach ( keys , function ( key ) {
374+ $rootScope . $apply . reset ( ) ;
375+
376+ var fn = fullCalendarConfig [ key ] ;
377+
378+ expect ( fn ( ) ) . toBe ( key ) ;
379+ expect ( $rootScope . $apply . callCount ) . toBe ( 1 ) ;
380+ expect ( scope . uiConfig . calendar [ key ] . callCount ) . toBe ( 1 ) ;
381+
382+ expect ( $rootScope . $apply ( function ( ) {
383+ expect ( $rootScope . $apply . callCount ) . toBe ( 2 ) ;
384+ return fn ( ) ;
385+ } ) ) . toBe ( key ) ;
386+ expect ( $rootScope . $apply . callCount ) . toBe ( 2 ) ;
387+ expect ( scope . uiConfig . calendar [ key ] . callCount ) . toBe ( 2 ) ;
388+ } ) ;
386389 } ) ) ;
387390 } ) ;
388391
0 commit comments