feat($browser): xhr returns raw request object

This commit is contained in:
Vojta Jina 2011-08-03 13:53:59 +02:00 committed by Igor Minar
parent a035e88397
commit 0c8b35681e
3 changed files with 10 additions and 0 deletions

View file

@ -120,6 +120,7 @@ angular.module.ngMock.$Browser = function() {
});
callback(expectation.code, expectation.response);
});
// TODO(vojta): return mock request object
};
self.xhr.expectations = expectations;
self.xhr.requests = requests;

View file

@ -90,8 +90,12 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
* <li><tt>X-Requested-With</tt>: <tt>XMLHttpRequest</tt></li>
* </ul>
*
* @returns {XMLHttpRequest|undefined} Raw XMLHttpRequest object or undefined when JSONP method
*
* @description
* Send ajax request
*
* TODO(vojta): change signature of this method to (method, url, data, headers, callback)
*/
self.xhr = function(method, url, post, callback, headers) {
outstandingRequestCount ++;
@ -124,6 +128,7 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
}
};
xhr.send(post || '');
return xhr;
}
};

View file

@ -223,6 +223,10 @@ describe('browser', function() {
expect(code).toEqual(202);
expect(response).toEqual('RESPONSE');
});
it('should return raw xhr object', function() {
expect(browser.xhr('GET', '/url', null, noop)).toBe(xhr);
});
});
describe('defer', function() {