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

Commit 363fb16

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

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
@@ -1871,6 +1871,15 @@ function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) {
18711871

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

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

@@ -1886,7 +1895,7 @@ function MockHttpExpectation(method, url, data, headers, keys) {
18861895
if (!url) return true;
18871896
if (angular.isFunction(url.test)) return url.test(u);
18881897
if (angular.isFunction(url)) return url(u);
1889-
return url == u;
1898+
return (url == u || compareUrl(u));
18901899
};
18911900

18921901
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)