Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0c8b356

Browse files
vojtajinaIgorMinar
authored andcommitted
feat($browser): xhr returns raw request object
1 parent a035e88 commit 0c8b356

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/angular-mocks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ angular.module.ngMock.$Browser = function() {
120120
});
121121
callback(expectation.code, expectation.response);
122122
});
123+
// TODO(vojta): return mock request object
123124
};
124125
self.xhr.expectations = expectations;
125126
self.xhr.requests = requests;

src/service/browser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
9090
* <li><tt>X-Requested-With</tt>: <tt>XMLHttpRequest</tt></li>
9191
* </ul>
9292
*
93+
* @returns {XMLHttpRequest|undefined} Raw XMLHttpRequest object or undefined when JSONP method
94+
*
9395
* @description
9496
* Send ajax request
97+
*
98+
* TODO(vojta): change signature of this method to (method, url, data, headers, callback)
9599
*/
96100
self.xhr = function(method, url, post, callback, headers) {
97101
outstandingRequestCount ++;
@@ -124,6 +128,7 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
124128
}
125129
};
126130
xhr.send(post || '');
131+
return xhr;
127132
}
128133
};
129134

test/service/browserSpecs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ describe('browser', function() {
223223
expect(code).toEqual(202);
224224
expect(response).toEqual('RESPONSE');
225225
});
226+
227+
it('should return raw xhr object', function() {
228+
expect(browser.xhr('GET', '/url', null, noop)).toBe(xhr);
229+
});
226230
});
227231

228232
describe('defer', function() {

0 commit comments

Comments
 (0)