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

Commit 1581827

Browse files
deodeveloperpetebacondarwin
authored andcommitted
fix(ngMock): match HTTP request regardless of the order of query params
Closes #12762
1 parent eaa1119 commit 1581827

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/ngMock/angular-mocks.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,15 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
18721872

18731873
function MockHttpExpectation(method, url, data, headers, keys) {
18741874

1875+
function getUrlParams(u) {
1876+
var params = u.slice(u.indexOf('?') + 1).split('&');
1877+
return params.sort();
1878+
}
1879+
1880+
function compareUrl(u) {
1881+
return (url.slice(0, url.indexOf('?')) == u.slice(0, u.indexOf('?')) && getUrlParams(url).join() == getUrlParams(u).join());
1882+
}
1883+
18751884
this.data = data;
18761885
this.headers = headers;
18771886

@@ -1887,7 +1896,7 @@ function MockHttpExpectation(method, url, data, headers, keys) {
18871896
if (!url) return true;
18881897
if (angular.isFunction(url.test)) return url.test(u);
18891898
if (angular.isFunction(url)) return url(u);
1890-
return url == u;
1899+
return (url == u || compareUrl(u));
18911900
};
18921901

18931902
this.matchHeaders = function(h) {

test/ngMock/angular-mocksSpec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,11 @@ describe('ngMock', function() {
16331633
expect(exp.match('GET', 'a/x')).toBe(false);
16341634
});
16351635

1636+
it('should match url with same query params, but different order', function() {
1637+
var exp = new MockHttpExpectation('GET', 'www.example.com/x/y?a=b&c=d&e=f');
1638+
1639+
expect(exp.matchUrl('www.example.com/x/y?e=f&c=d&a=b')).toBe(true);
1640+
});
16361641

16371642
it('should accept url as function', function() {
16381643
var urlValidator = function(url) {

0 commit comments

Comments
 (0)