From e0a54f6b206dc2b6595f2bc3a17c5932e7477545 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sat, 4 Aug 2012 12:11:00 -0700 Subject: feat($http): support reponseType Closes #1013 --- test/ng/httpBackendSpec.js | 18 ++++++++++++++++++ test/ng/httpSpec.js | 9 ++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 06b63c3c..a491ae26 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -135,6 +135,24 @@ describe('$httpBackend', function() { }); + it('should set responseType and return xhr.response', function() { + $backend('GET', '/whatever', null, callback, {}, null, null, 'blob'); + + var xhrInstance = MockXhr.$$lastInstance; + expect(xhrInstance.responseType).toBe('blob'); + + callback.andCallFake(function(status, response) { + expect(response).toBe(xhrInstance.response); + }); + + xhrInstance.response = {some: 'object'}; + xhrInstance.readyState = 4; + xhrInstance.onreadystatechange(); + + expect(callback).toHaveBeenCalledOnce(); + }); + + describe('JSONP', function() { var SCRIPT_URL = /([^\?]*)\?cb=angular\.callbacks\.(.*)/; diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index bb4de3c1..f7df3d4b 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -959,12 +959,13 @@ describe('$http', function() { }); - it('should pass timeout and withCredentials', function() { + it('should pass timeout, withCredentials and responseType', function() { var $httpBackend = jasmine.createSpy('$httpBackend'); - $httpBackend.andCallFake(function(m, u, d, c, h, timeout, withCredentials) { + $httpBackend.andCallFake(function(m, u, d, c, h, timeout, withCredentials, responseType) { expect(timeout).toBe(12345); expect(withCredentials).toBe(true); + expect(responseType).toBe('json'); }); module(function($provide) { @@ -972,7 +973,9 @@ describe('$http', function() { }); inject(function($http) { - $http({method: 'GET', url: 'some.html', timeout: 12345, withCredentials: true}); + $http({ + method: 'GET', url: 'some.html', timeout: 12345, withCredentials: true, responseType: 'json' + }); expect($httpBackend).toHaveBeenCalledOnce(); }); -- cgit v1.2.3