You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
We are transforming the response (here, we compute an UTC timestamp from a date formatted as 'yyyy-mm-dd').
Suppose this simple test :
it('should compute UTC date',function(){$httpBackend.whenGET('/resource').respond({date: '2016-01-01'});$scope.find();$httpBackend.flush();expect(angular.isNumber($scope.result.date)).toBe(true);// make a second call, it will fail$scope.find();$httpBackend.flush();});
Here is the reason :
Response defined in the whenGET method is an object that will be returned by angular-mocks.
Since the http request is a cached request, this object will be put in the $http cache.
The success callback set the date as a timestamp on the object in the cache.
If I make a second call, the object in the cache is returned : the date attribute is now a number.
I can fix this in my test by using angular.toJson to specify that the response is not an object but a json string, but the problem could be solved in angular-mocks :
What do you think ? Should I fix this in my test or a PR is welcome ?
Note that this is a problem with angular-mocks, not with $http since the object stored in the $http cache is the server response (which is a string in a browser, deserialized in the defaultHttpResponseTransform function).