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

Commit

Permalink
fix($httpBackend): Set current url, if not defined or empty string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vojtajina committed Feb 24, 2012
1 parent d6e3e1b commit 3171f21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/service/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, body, locati
// TODO(vojta): fix the signature
return function(method, url, post, callback, headers, timeout) {
$browser.$$incOutstandingRequestCount();
url = url || $browser.url();

if (lowercase(method) == 'jsonp') {
var callbackId = '_' + (callbacks.counter++).toString(36);
Expand Down
11 changes: 11 additions & 0 deletions test/service/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ describe('$httpBackend', function() {
});


it('should set url to current location if not specified or empty string', function() {
$backend('JSONP', undefined, null, callback);
expect($browser.$$scripts[0].url).toBe($browser.url());
$browser.$$scripts.shift();

$backend('JSONP', '', null, callback);
expect($browser.$$scripts[0].url).toBe($browser.url());
$browser.$$scripts.shift();
});


// TODO(vojta): test whether it fires "async-start"
// TODO(vojta): test whether it fires "async-end" on both success and error
});
Expand Down

0 comments on commit 3171f21

Please sign in to comment.