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

Commit 1426b02

Browse files
bcaudanpetebacondarwin
authored andcommitted
fix(ngMock): $httpBackend should match data containing Date objects correctly
If a response or expectation contained a date object then `$httpBackend.expect` was not matching correctly. This commit encodes then decodes the object being matched to ensure consistency. Closes #5127
1 parent 29aeee2 commit 1426b02

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ngMock/angular-mocks.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,9 @@ function MockHttpExpectation(method, url, data, headers) {
15631563
if (angular.isUndefined(data)) return true;
15641564
if (data && angular.isFunction(data.test)) return data.test(d);
15651565
if (data && angular.isFunction(data)) return data(d);
1566-
if (data && !angular.isString(data)) return angular.equals(data, angular.fromJson(d));
1566+
if (data && !angular.isString(data)) {
1567+
return angular.equals(angular.fromJson(angular.toJson(data)), angular.fromJson(d));
1568+
}
15671569
return data == d;
15681570
};
15691571

test/ng/httpSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,12 @@ describe('$http', function() {
10531053
});
10541054

10551055

1056+
it('should transform object with date into json', function() {
1057+
$httpBackend.expect('POST', '/url', {"date": new Date(Date.UTC(2013, 11, 25))}).respond('');
1058+
$http({method: 'POST', url: '/url', data: {date: new Date(Date.UTC(2013, 11, 25))}});
1059+
});
1060+
1061+
10561062
it('should ignore strings', function() {
10571063
$httpBackend.expect('POST', '/url', 'string-data').respond('');
10581064
$http({method: 'POST', url: '/url', data: 'string-data'});

0 commit comments

Comments
 (0)