mardi 24 mars 2015

Unexpected Request Error with $HttpBackend (AngularJS)

I am using HttpBackend to mock some Http responses for some calls that my Angular app is making.


However, I am getting the error "Unexpected Request: [object Object] undefined".


I know that usually this error means you're missing or mistyped one of the $http requests that the app makes so it can't find a response. But my error is not specific like the other ones which usually say like "Unexpected Request: GET api/call" so I don't know what is wrong.


Has anyone ever encountered this specific error before?


Sample Code


angular controller:



app.controller( 'ctrl',
[ '$scope' , '$http' , '$location', function( $scope, $http, $location ) {
$http.get(
"/api/1.0/id/" + id,
{
headers: getAuthHeaders()
}
).success(function( data ){ //... })]
);


jasmine test:



it('should ...', function(){
httpBackend.whenGET('/api/1.0/id/*').respond(200,{"test":"Test"});
//...
});

Aucun commentaire:

Enregistrer un commentaire