Permalink
Browse files
fix(ngMock): match HTTP request regardless of the order of query params
- Loading branch information
Showing
with
15 additions
and
1 deletion.
-
+10
−1
src/ngMock/angular-mocks.js
-
+5
−0
test/ngMock/angular-mocksSpec.js
|
|
@@ -1872,6 +1872,15 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) { |
|
|
|
|
|
function MockHttpExpectation(method, url, data, headers, keys) { |
|
|
|
|
|
function getUrlParams(u) { |
|
|
var params = u.slice(u.indexOf('?') + 1).split('&'); |
|
|
return params.sort(); |
|
|
} |
|
|
|
|
|
function compareUrl(u) { |
|
|
return (url.slice(0, url.indexOf('?')) == u.slice(0, u.indexOf('?')) && getUrlParams(url).join() == getUrlParams(u).join()); |
|
|
} |
|
|
|
|
|
this.data = data; |
|
|
this.headers = headers; |
|
|
|
|
|
@@ -1887,7 +1896,7 @@ function MockHttpExpectation(method, url, data, headers, keys) { |
|
|
if (!url) return true; |
|
|
if (angular.isFunction(url.test)) return url.test(u); |
|
|
if (angular.isFunction(url)) return url(u); |
|
|
return url == u; |
|
|
return (url == u || compareUrl(u)); |
|
|
}; |
|
|
|
|
|
this.matchHeaders = function(h) { |
|
|
|
|
|
@@ -1633,6 +1633,11 @@ describe('ngMock', function() { |
|
|
expect(exp.match('GET', 'a/x')).toBe(false); |
|
|
}); |
|
|
|
|
|
it('should match url with same query params, but different order', function() { |
|
|
var exp = new MockHttpExpectation('GET', 'www.example.com/x/y?a=b&c=d&e=f'); |
|
|
|
|
|
expect(exp.matchUrl('www.example.com/x/y?e=f&c=d&a=b')).toBe(true); |
|
|
}); |
|
|
|
|
|
it('should accept url as function', function() { |
|
|
var urlValidator = function(url) { |
|
|
|