3
3
describe ( 'ngView' , function ( ) {
4
4
var element ;
5
5
6
- beforeEach ( module ( function ( ) {
6
+ beforeEach ( module ( function ( $provide ) {
7
+ $provide . value ( '$window' , angular . mock . createMockWindow ( ) ) ;
7
8
return function ( $rootScope , $compile , $animator ) {
8
9
element = $compile ( '<ng:view onload="load()"></ng:view>' ) ( $rootScope ) ;
9
10
$animator . enabled ( true ) ;
@@ -621,5 +622,46 @@ describe('ngView', function() {
621
622
}
622
623
} ) ) ;
623
624
625
+
626
+ it ( 'should not double compile when route changes' , function ( ) {
627
+ module ( function ( $routeProvider , $animationProvider , $provide ) {
628
+ $routeProvider . when ( '/foo' , { template : '<div ng-repeat="i in [1,2]">{{i}}</div>' } ) ;
629
+ $routeProvider . when ( '/bar' , { template : '<div ng-repeat="i in [3,4]">{{i}}</div>' } ) ;
630
+ $animationProvider . register ( 'my-animation-leave' , function ( ) {
631
+ return {
632
+ start : function ( element , done ) {
633
+ done ( ) ;
634
+ }
635
+ } ;
636
+ } ) ;
637
+ } ) ;
638
+
639
+ inject ( function ( $rootScope , $compile , $location , $route , $window , $rootElement , $sniffer ) {
640
+ element = $compile ( html ( '<ng:view onload="load()" ng-animate="\'my-animation\'"></ng:view>' ) ) ( $rootScope ) ;
641
+
642
+ $location . path ( '/foo' ) ;
643
+ $rootScope . $digest ( ) ;
644
+ if ( $sniffer . supportsTransitions ) {
645
+ $window . setTimeout . expect ( 1 ) . process ( ) ;
646
+ $window . setTimeout . expect ( 0 ) . process ( ) ;
647
+ }
648
+ expect ( element . text ( ) ) . toEqual ( '12' ) ;
649
+
650
+ $location . path ( '/bar' ) ;
651
+ $rootScope . $digest ( ) ;
652
+ expect ( n ( element . text ( ) ) ) . toEqual ( '1234' ) ;
653
+ if ( $sniffer . supportsTransitions ) {
654
+ $window . setTimeout . expect ( 1 ) . process ( ) ;
655
+ $window . setTimeout . expect ( 1 ) . process ( ) ;
656
+ } else {
657
+ $window . setTimeout . expect ( 1 ) . process ( ) ;
658
+ }
659
+ expect ( element . text ( ) ) . toEqual ( '34' ) ;
660
+
661
+ function n ( text ) {
662
+ return text . replace ( / \r \n / m, '' ) . replace ( / \r \n / m, '' ) ;
663
+ }
664
+ } ) ;
665
+ } ) ;
624
666
} ) ;
625
- } ) ;
667
+ } ) ;
0 commit comments