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

Commit 3171f21

Browse files
committed
fix($httpBackend): Set current url, if not defined or empty string
Reason to fix this was the fact that with undefined url, it ended up with weird exception (Cannot call method 'replace' of undefined), which was more confusing than helpful. jQuery.ajax() does request to current url, if url is not specified, so I decided for this solution.
1 parent d6e3e1b commit 3171f21

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/service/httpBackend.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, body, locati
3434
// TODO(vojta): fix the signature
3535
return function(method, url, post, callback, headers, timeout) {
3636
$browser.$$incOutstandingRequestCount();
37+
url = url || $browser.url();
3738

3839
if (lowercase(method) == 'jsonp') {
3940
var callbackId = '_' + (callbacks.counter++).toString(36);

test/service/httpBackendSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ describe('$httpBackend', function() {
168168
});
169169

170170

171+
it('should set url to current location if not specified or empty string', function() {
172+
$backend('JSONP', undefined, null, callback);
173+
expect($browser.$$scripts[0].url).toBe($browser.url());
174+
$browser.$$scripts.shift();
175+
176+
$backend('JSONP', '', null, callback);
177+
expect($browser.$$scripts[0].url).toBe($browser.url());
178+
$browser.$$scripts.shift();
179+
});
180+
181+
171182
// TODO(vojta): test whether it fires "async-start"
172183
// TODO(vojta): test whether it fires "async-end" on both success and error
173184
});

0 commit comments

Comments
 (0)