@@ -155,10 +155,11 @@ describe('$httpBackend', function() {
155
155
} ) ;
156
156
157
157
it ( 'should not try to read response data when request is aborted' , function ( ) {
158
- callback . and . callFake ( function ( status , response , headers ) {
158
+ callback . and . callFake ( function ( status , response , headers , statusText ) {
159
159
expect ( status ) . toBe ( - 1 ) ;
160
160
expect ( response ) . toBe ( null ) ;
161
161
expect ( headers ) . toBe ( null ) ;
162
+ expect ( statusText ) . toBe ( '' ) ;
162
163
} ) ;
163
164
$backend ( 'GET' , '/url' , null , callback , { } , 2000 ) ;
164
165
xhr = MockXhr . $$lastInstance ;
@@ -172,6 +173,22 @@ describe('$httpBackend', function() {
172
173
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
173
174
} ) ;
174
175
176
+ it ( 'should complete the request on timeout' , function ( ) {
177
+ callback . and . callFake ( function ( status , response , headers , statusText ) {
178
+ expect ( status ) . toBe ( - 1 ) ;
179
+ expect ( response ) . toBe ( null ) ;
180
+ expect ( headers ) . toBe ( null ) ;
181
+ expect ( statusText ) . toBe ( '' ) ;
182
+ } ) ;
183
+ $backend ( 'GET' , '/url' , null , callback , { } ) ;
184
+ xhr = MockXhr . $$lastInstance ;
185
+
186
+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
187
+
188
+ xhr . ontimeout ( ) ;
189
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
190
+ } ) ;
191
+
175
192
it ( 'should abort request on timeout' , function ( ) {
176
193
callback . and . callFake ( function ( status , response ) {
177
194
expect ( status ) . toBe ( - 1 ) ;
@@ -253,6 +270,7 @@ describe('$httpBackend', function() {
253
270
expect ( MockXhr . $$lastInstance . withCredentials ) . toBe ( true ) ;
254
271
} ) ;
255
272
273
+
256
274
it ( 'should call $xhrFactory with method and url' , function ( ) {
257
275
var mockXhrFactory = jasmine . createSpy ( 'mockXhrFactory' ) . and . callFake ( createMockXhr ) ;
258
276
$backend = createHttpBackend ( $browser , mockXhrFactory , $browser . defer , $jsonpCallbacks , fakeDocument ) ;
@@ -391,6 +409,7 @@ describe('$httpBackend', function() {
391
409
// TODO(vojta): test whether it fires "async-end" on both success and error
392
410
} ) ;
393
411
412
+
394
413
describe ( 'protocols that return 0 status code' , function ( ) {
395
414
396
415
function respond ( status , content ) {
@@ -400,10 +419,12 @@ describe('$httpBackend', function() {
400
419
xhr . onload ( ) ;
401
420
}
402
421
403
-
404
- it ( 'should convert 0 to 200 if content and file protocol' , function ( ) {
422
+ beforeEach ( function ( ) {
405
423
$backend = createHttpBackend ( $browser , createMockXhr ) ;
424
+ } ) ;
425
+
406
426
427
+ it ( 'should convert 0 to 200 if content and file protocol' , function ( ) {
407
428
$backend ( 'GET' , 'file:///whatever/index.html' , null , callback ) ;
408
429
respond ( 0 , 'SOME CONTENT' ) ;
409
430
@@ -412,8 +433,6 @@ describe('$httpBackend', function() {
412
433
} ) ;
413
434
414
435
it ( 'should convert 0 to 200 if content for protocols other than file' , function ( ) {
415
- $backend = createHttpBackend ( $browser , createMockXhr ) ;
416
-
417
436
$backend ( 'GET' , 'someProtocol:///whatever/index.html' , null , callback ) ;
418
437
respond ( 0 , 'SOME CONTENT' ) ;
419
438
@@ -422,8 +441,6 @@ describe('$httpBackend', function() {
422
441
} ) ;
423
442
424
443
it ( 'should convert 0 to 404 if no content and file protocol' , function ( ) {
425
- $backend = createHttpBackend ( $browser , createMockXhr ) ;
426
-
427
444
$backend ( 'GET' , 'file:///whatever/index.html' , null , callback ) ;
428
445
respond ( 0 , '' ) ;
429
446
@@ -432,8 +449,6 @@ describe('$httpBackend', function() {
432
449
} ) ;
433
450
434
451
it ( 'should not convert 0 to 404 if no content for protocols other than file' , function ( ) {
435
- $backend = createHttpBackend ( $browser , createMockXhr ) ;
436
-
437
452
$backend ( 'GET' , 'someProtocol:///whatever/index.html' , null , callback ) ;
438
453
respond ( 0 , '' ) ;
439
454
@@ -460,8 +475,6 @@ describe('$httpBackend', function() {
460
475
461
476
try {
462
477
463
- $backend = createHttpBackend ( $browser , createMockXhr ) ;
464
-
465
478
$backend ( 'GET' , '/whatever/index.html' , null , callback ) ;
466
479
respond ( 0 , '' ) ;
467
480
@@ -473,10 +486,7 @@ describe('$httpBackend', function() {
473
486
}
474
487
} ) ;
475
488
476
-
477
489
it ( 'should return original backend status code if different from 0' , function ( ) {
478
- $backend = createHttpBackend ( $browser , createMockXhr ) ;
479
-
480
490
// request to http://
481
491
$backend ( 'POST' , 'http://rest_api/create_whatever' , null , callback ) ;
482
492
respond ( 201 , '' ) ;
0 commit comments