title: Error: Unexpected request: POST http://server:80/api/metrics No more request expected
body: <p>Hi I have a found several related questions and tried to mimic the solutions that worked for these questions but I am confused why I get this error when I set up my expectation correctly.</p>
  
  <p>My test</p>
  
  <pre><code>describe("Controller", function () {
  var scope, SearchCtrl, httpBackend, searchSerivce;
  
  //load the controller"s module
  beforeEach(module("myApp"));
  
  beforeEach(function () {
      angular.mock.inject(function ($injector) {
          httpBackend = $injector.get("$httpBackend");
      });
  });
  
  //initialize the controller and a mock scope
  beforeEach(inject(function ($controller, $rootScope, $injector) {
  
      // create a new child scope
      scope = $rootScope.$new();
  
  
      scope.SearchService = $injector.get("SearchService");
  
      //create a new instance of basic search controller
      SearchCtrl = $controller("BasicSearchCtrl", { $scope: scope });
  
  
  }));
  
  
  //check the search after setting the same text
  it("setting some text content in search to check it is updated in searchservice basicSearch", function () {
  
      scope.search = "test";
  
      httpBackend.when('GET', 'http://server:80/api/metrics').respond(200);
  
      scope.$digest();
  
      expect(scope.SearchService.basicSearch).toBe("test");
  
  });
  </code></pre>
  
  <p>As you can see I'm setting up the expectation for this metrics page with the following line</p>
  
  <pre><code>httpBackend.when('GET', 'http://server:80/api/metrics').respond(200);
  </code></pre>
  
  <p>I've also tried</p>
  
  <pre><code>    httpBackend.expectGET('http://server:80/api/metrics');
      httpBackend.whenGET('http://server:80/api/metrics').respond(200);
  </code></pre>
  
  <p>And </p>
  
  <pre><code>    httpBackend.expectGET('api/metrics');
      httpBackend.whenGET('api/metrics').respond(200);
  </code></pre>
  
  <p>And</p>
  
  <pre><code>    httpBackend.expectGET('/api/metrics');
      httpBackend.whenGET('/api/metrics').respond(200);
  </code></pre>
  
  <p>But they all give me this error</p>
  
  <pre><code>Error: Unexpected request: POST http://server:80/api/metrics
  No more request expected
  </code></pre>
  
  <p>Any pointers will be greatly appreciated!</p>
  
  <p><em>Update</em></p>
  
  <p>Solution...it was a POST not get so</p>
  
  <pre><code>    //set up an expectation and response for this POST
      httpBackend.expectPOST('http://server:80/api/metrics').respond(200);
  </code></pre>
  
  <p>worked</p>