0

I'm trying to use ng-mock to fake a DELETE request but keep getting Error: Unexpected request: DELETE /api/1.0/package/1. How do I properly define the mock url to match the factory request:

function deletePackage(file) {
  return $http.delete('/api/1.0/package/' + file.id)
    .then(deleteComplete)
    .catch(deleteFailed)            
}

$httpBackend.whenDELETE('/api/1.0/package/:id').respond(function(method, url, data, headers, params) {
   return [200, params.id];
});
neridaj
  • 2,143
  • 9
  • 31
  • 62

2 Answers2

0

So presumably you know what file argument you're going to pass to the deletePackage method. With that in mind, you should then know exactly what URI to expect.

var file = {id: 'some_id'};
$httpBackend.whenDELETE('/api/1.0/package/' + file.id).respond(file.id);

deletePackage(file); // presuming this function is in scope
Phil
  • 157,677
  • 23
  • 242
  • 245
0

I was looking at the wrong version of the docs (1.5) and I had to remove the single quotes around the regex:

$httpBackend.whenDELETE(/\/api\/1.0\/package\/(.+)/)
.respond(function(method, url, data) {
   return [200];
});
neridaj
  • 2,143
  • 9
  • 31
  • 62