@@ -264,21 +264,45 @@ describe('$httpBackend', function() {
264
264
} ) ;
265
265
266
266
267
- it ( 'should set responseType and return xhr.response' , function ( ) {
268
- $backend ( 'GET' , '/whatever' , null , callback , { } , null , null , 'blob' ) ;
267
+ describe ( 'responseType' , function ( ) {
269
268
270
- var xhrInstance = MockXhr . $$lastInstance ;
271
- expect ( xhrInstance . responseType ) . toBe ( 'blob' ) ;
269
+ it ( 'should set responseType and return xhr.response' , function ( ) {
270
+ $backend ( 'GET' , '/whatever' , null , callback , { } , null , null , 'blob' ) ;
272
271
273
- callback . andCallFake ( function ( status , response ) {
274
- expect ( response ) . toBe ( xhrInstance . response ) ;
272
+ var xhrInstance = MockXhr . $$lastInstance ;
273
+ expect ( xhrInstance . responseType ) . toBe ( 'blob' ) ;
274
+
275
+ callback . andCallFake ( function ( status , response ) {
276
+ expect ( response ) . toBe ( xhrInstance . response ) ;
277
+ } ) ;
278
+
279
+ xhrInstance . response = { some : 'object' } ;
280
+ xhrInstance . readyState = 4 ;
281
+ xhrInstance . onreadystatechange ( ) ;
282
+
283
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
275
284
} ) ;
276
285
277
- xhrInstance . response = { some : 'object' } ;
278
- xhrInstance . readyState = 4 ;
279
- xhrInstance . onreadystatechange ( ) ;
280
286
281
- expect ( callback ) . toHaveBeenCalledOnce ( ) ;
287
+ it ( 'should read responseText if response was not defined' , function ( ) {
288
+ // old browsers like IE8, don't support responseType, so they always respond with responseText
289
+
290
+ $backend ( 'GET' , '/whatever' , null , callback , { } , null , null , 'blob' ) ;
291
+
292
+ var xhrInstance = MockXhr . $$lastInstance ;
293
+ var responseText = '{"some": "object"}' ;
294
+ expect ( xhrInstance . responseType ) . toBe ( 'blob' ) ;
295
+
296
+ callback . andCallFake ( function ( status , response ) {
297
+ expect ( response ) . toBe ( responseText ) ;
298
+ } ) ;
299
+
300
+ xhrInstance . responseText = responseText ;
301
+ xhrInstance . readyState = 4 ;
302
+ xhrInstance . onreadystatechange ( ) ;
303
+
304
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
305
+ } ) ;
282
306
} ) ;
283
307
284
308
0 commit comments