@@ -67,7 +67,7 @@ describe('widget', function() {
67
67
it ( 'should include on external file' , inject ( putIntoCache ( 'myUrl' , '{{name}}' ) ,
68
68
function ( $rootScope , $compile , $browser ) {
69
69
var element = jqLite ( '<ng:include src="url" scope="childScope"></ng:include>' ) ;
70
- var element = $compile ( element ) ( $rootScope ) ;
70
+ element = $compile ( element ) ( $rootScope ) ;
71
71
$rootScope . childScope = $rootScope . $new ( ) ;
72
72
$rootScope . childScope . name = 'misko' ;
73
73
$rootScope . url = 'myUrl' ;
@@ -81,7 +81,7 @@ describe('widget', function() {
81
81
putIntoCache ( 'myUrl' , '{{name}}' ) ,
82
82
function ( $rootScope , $compile , $browser ) {
83
83
var element = jqLite ( '<ng:include src="url" scope="childScope"></ng:include>' ) ;
84
- var element = $compile ( element ) ( $rootScope ) ;
84
+ element = $compile ( element ) ( $rootScope ) ;
85
85
$rootScope . childScope = $rootScope . $new ( ) ;
86
86
$rootScope . childScope . name = 'igor' ;
87
87
$rootScope . url = 'myUrl' ;
@@ -100,7 +100,7 @@ describe('widget', function() {
100
100
it ( 'should allow this for scope' , inject ( putIntoCache ( 'myUrl' , '{{"abc"}}' ) ,
101
101
function ( $rootScope , $compile , $browser ) {
102
102
var element = jqLite ( '<ng:include src="url" scope="this"></ng:include>' ) ;
103
- var element = $compile ( element ) ( $rootScope ) ;
103
+ element = $compile ( element ) ( $rootScope ) ;
104
104
$rootScope . url = 'myUrl' ;
105
105
$rootScope . $digest ( ) ;
106
106
$browser . defer . flush ( ) ;
@@ -119,7 +119,7 @@ describe('widget', function() {
119
119
putIntoCache ( 'myUrl' , 'my partial' ) ,
120
120
function ( $rootScope , $compile , $browser ) {
121
121
var element = jqLite ( '<ng:include src="url" onload="loaded = true"></ng:include>' ) ;
122
- var element = $compile ( element ) ( $rootScope ) ;
122
+ element = $compile ( element ) ( $rootScope ) ;
123
123
124
124
expect ( $rootScope . loaded ) . not . toBeDefined ( ) ;
125
125
@@ -135,7 +135,7 @@ describe('widget', function() {
135
135
it ( 'should destroy old scope' , inject ( putIntoCache ( 'myUrl' , 'my partial' ) ,
136
136
function ( $rootScope , $compile , $browser ) {
137
137
var element = jqLite ( '<ng:include src="url"></ng:include>' ) ;
138
- var element = $compile ( element ) ( $rootScope ) ;
138
+ element = $compile ( element ) ( $rootScope ) ;
139
139
140
140
expect ( $rootScope . $$childHead ) . toBeFalsy ( ) ;
141
141
@@ -199,6 +199,30 @@ describe('widget', function() {
199
199
$browser . defer . flush ( ) ;
200
200
expect ( element . text ( ) ) . toBe ( 'my partial' ) ;
201
201
} ) ) ;
202
+
203
+ it ( 'should discard pending xhr callbacks if a new template is requested before the current ' +
204
+ 'finished loading' , inject ( function ( $rootScope , $compile , $httpBackend ) {
205
+ var element = jqLite ( "<ng:include src='templateUrl'></ng:include>" ) ,
206
+ log = [ ] ;
207
+
208
+ $rootScope . templateUrl = 'myUrl1' ;
209
+ $rootScope . logger = function ( msg ) {
210
+ log . push ( msg ) ;
211
+ }
212
+ $compile ( element ) ( $rootScope ) ;
213
+ expect ( log . join ( '; ' ) ) . toEqual ( '' ) ;
214
+
215
+ $httpBackend . expect ( 'GET' , 'myUrl1' ) . respond ( '<div>{{logger("url1")}}</div>' ) ;
216
+ $rootScope . $digest ( ) ;
217
+ expect ( log . join ( '; ' ) ) . toEqual ( '' ) ;
218
+ $rootScope . templateUrl = 'myUrl2' ;
219
+ $httpBackend . expect ( 'GET' , 'myUrl2' ) . respond ( '<div>{{logger("url2")}}</div>' ) ;
220
+ $rootScope . $digest ( ) ;
221
+ $httpBackend . flush ( ) ; // now that we have two requests pending, flush!
222
+
223
+ expect ( log . join ( '; ' ) ) . toEqual ( 'url2; url2' ) ; // it's here twice because we go through at
224
+ // least two digest cycles
225
+ } ) ) ;
202
226
} ) ) ;
203
227
204
228
@@ -645,7 +669,7 @@ describe('widget', function() {
645
669
$location . path ( '/bar' ) ;
646
670
$httpBackend . expect ( 'GET' , 'myUrl2' ) . respond ( '<div>{{1+1}}</div>' ) ;
647
671
$rootScope . $digest ( ) ;
648
- $httpBackend . flush ( ) ; // now that we have to requests pending, flush!
672
+ $httpBackend . flush ( ) ; // now that we have two requests pending, flush!
649
673
650
674
expect ( $rootScope . $element . text ( ) ) . toEqual ( '2' ) ;
651
675
} ) ) ;
0 commit comments