fix(ngMock): match HTTP request regardless of the order of query params
Closes #12762
This commit is contained in:
committed by
Peter Bacon Darwin
parent
eaa1119d42
commit
1581827a51
Vendored
+10
-1
@@ -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) {
|
||||
|
||||
Vendored
+5
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user