mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
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
This commit is contained in:
committed by
Peter Bacon Darwin
parent
a7f886e6c8
commit
1025f6ebf4
4
src/ngMock/angular-mocks.js
vendored
4
src/ngMock/angular-mocks.js
vendored
@@ -1629,7 +1629,9 @@ function MockHttpExpectation(method, url, data, headers) {
|
||||
if (angular.isUndefined(data)) return true;
|
||||
if (data && angular.isFunction(data.test)) return data.test(d);
|
||||
if (data && angular.isFunction(data)) return data(d);
|
||||
if (data && !angular.isString(data)) return angular.equals(data, angular.fromJson(d));
|
||||
if (data && !angular.isString(data)) {
|
||||
return angular.equals(angular.fromJson(angular.toJson(data)), angular.fromJson(d));
|
||||
}
|
||||
return data == d;
|
||||
};
|
||||
|
||||
|
||||
@@ -929,6 +929,12 @@ describe('$http', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should transform object with date into json', function() {
|
||||
$httpBackend.expect('POST', '/url', {"date": new Date(Date.UTC(2013, 11, 25))}).respond('');
|
||||
$http({method: 'POST', url: '/url', data: {date: new Date(Date.UTC(2013, 11, 25))}});
|
||||
});
|
||||
|
||||
|
||||
it('should ignore strings', function() {
|
||||
$httpBackend.expect('POST', '/url', 'string-data').respond('');
|
||||
$http({method: 'POST', url: '/url', data: 'string-data'});
|
||||
|
||||
Reference in New Issue
Block a user