@@ -416,8 +416,16 @@ describe('uiSrefActive', function() {
416416 } ) ;
417417 } ) ) ;
418418
419- beforeEach ( inject ( function ( $document ) {
419+ beforeEach ( inject ( function ( $document , $timeout ) {
420420 document = $document [ 0 ] ;
421+ timeoutFlush = function ( ) {
422+ try {
423+ $timeout . flush ( ) ;
424+ } catch ( e ) {
425+ // Angular 1.0.8 throws 'No deferred tasks to be flushed' if there is nothing in queue.
426+ // Behave as Angular >=1.1.5 and do nothing in such case.
427+ }
428+ }
421429 } ) ) ;
422430
423431 it ( 'should update class for sibling uiSref' , inject ( function ( $rootScope , $q , $compile , $state ) {
@@ -428,11 +436,12 @@ describe('uiSrefActive', function() {
428436 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
429437 $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
430438 $q . flush ( ) ;
431-
439+ timeoutFlush ( ) ;
432440 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
433441
434442 $state . transitionTo ( 'contacts.item' , { id : 2 } ) ;
435443 $q . flush ( ) ;
444+ timeoutFlush ( ) ;
436445 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
437446 } ) ) ;
438447
@@ -444,10 +453,12 @@ describe('uiSrefActive', function() {
444453 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
445454 $state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'bar' } ) ;
446455 $q . flush ( ) ;
456+ timeoutFlush ( ) ;
447457 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
448458
449459 $state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'baz' } ) ;
450460 $q . flush ( ) ;
461+ timeoutFlush ( ) ;
451462 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
452463 } ) ) ;
453464
@@ -458,10 +469,12 @@ describe('uiSrefActive', function() {
458469
459470 $state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
460471 $q . flush ( ) ;
472+ timeoutFlush ( ) ;
461473 expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
462474
463475 $state . transitionTo ( 'contacts.item.edit' , { id : 4 } ) ;
464476 $q . flush ( ) ;
477+ timeoutFlush ( ) ;
465478 expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e / ) ;
466479 } ) ) ;
467480
@@ -472,28 +485,51 @@ describe('uiSrefActive', function() {
472485
473486 $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
474487 $q . flush ( ) ;
488+ timeoutFlush ( ) ;
475489 expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
476490
477491 $state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
478492 $q . flush ( ) ;
493+ timeoutFlush ( ) ;
479494 expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e / ) ;
480495 } ) ) ;
481496
497+ it ( 'should match on child states when active-equals and active-equals-eq is used' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
498+ template = $compile ( '<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active" ui-sref-active-eq="active-eq">Contacts</a></div>' ) ( $rootScope ) ;
499+ $rootScope . $digest ( ) ;
500+ var a = angular . element ( template [ 0 ] . getElementsByTagName ( 'a' ) [ 0 ] ) ;
501+
502+ $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
503+ $q . flush ( ) ;
504+ timeoutFlush ( ) ;
505+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
506+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e - e q / ) ;
507+
508+ $state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
509+ $q . flush ( ) ;
510+ timeoutFlush ( ) ;
511+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
512+ expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e - e q / ) ;
513+ } ) ) ;
514+
482515 it ( 'should resolve relative state refs' , inject ( function ( $rootScope , $q , $compile , $state ) {
483516 el = angular . element ( '<section><div ui-view></div></section>' ) ;
484517 template = $compile ( el ) ( $rootScope ) ;
485518 $rootScope . $digest ( ) ;
486519
487520 $state . transitionTo ( 'contacts' ) ;
488521 $q . flush ( ) ;
522+ timeoutFlush ( ) ;
489523 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
490524
491525 $state . transitionTo ( 'contacts.item' , { id : 6 } ) ;
492526 $q . flush ( ) ;
527+ timeoutFlush ( ) ;
493528 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
494529
495530 $state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
496531 $q . flush ( ) ;
532+ timeoutFlush ( ) ;
497533 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
498534 } ) ) ;
499535
@@ -506,10 +542,12 @@ describe('uiSrefActive', function() {
506542
507543 $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
508544 $q . flush ( ) ;
545+ timeoutFlush ( ) ;
509546 expect ( angular . element ( template [ 0 ] ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
510547
511548 $state . transitionTo ( 'contacts.item' , { id : 2 } ) ;
512549 $q . flush ( ) ;
550+ timeoutFlush ( ) ;
513551 expect ( angular . element ( template [ 0 ] ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
514552 } ) ) ;
515553
@@ -524,10 +562,12 @@ describe('uiSrefActive', function() {
524562
525563 $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
526564 $q . flush ( ) ;
565+ timeoutFlush ( ) ;
527566 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
528567
529568 $state . transitionTo ( 'contacts.lazy' ) ;
530569 $q . flush ( ) ;
570+ timeoutFlush ( ) ;
531571 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
532572 } ) ) ;
533573
@@ -542,10 +582,12 @@ describe('uiSrefActive', function() {
542582
543583 $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
544584 $q . flush ( ) ;
585+ timeoutFlush ( ) ;
545586 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
546587
547588 $state . transitionTo ( 'contacts.lazy' ) ;
548589 $q . flush ( ) ;
590+ timeoutFlush ( ) ;
549591 expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
550592 } ) ) ;
551593} ) ;
0 commit comments