title: Angular Unit Test: Error: Unexpected request: GET
body: <p>How can test this type of http format below?</p>
  
  <pre><code>$http({
      method: 'GET',
      url: 'https://api.github.com/user/repos',
      headers:{
          'Authorization': "Basic " + btoa("xxxx:xxxx"),
          'Accept': 'application/json; odata=verbose'
      }
  })
  .success(function(data, status, headers, config) {
      $scope.valid = true;
      $scope.collection = data;
  })
  .error(function(data, status, headers, config) {
      $scope.error = data;
  });
  </code></pre>
  
  <p>Test code,</p>
  
  <pre><code>it('should demonstrate using when (200 status)', inject(function($http, $httpBackend) {
  
      var $scope = {};
  
      /* Code Under Test */
      $http({
          method: 'GET',
          url: 'https://api.github.com/user/repos',
          headers:{
              'Authorization': "Basic " + btoa("xxxxx:xxxx"),
              'Accept': 'application/json; odata=verbose'
          }
      })
      .success(function(data, status, headers, config) {
          $scope.valid = true;
          $scope.collection = data;
      })
      .error(function(data, status, headers, config) {
          $scope.error = data;
      });
      /* End */
  
    $httpBackend
      .when('GET', 'https://api.github.com/user/repos', undefined, {
          Authorization: "Basic " + btoa("xxxxx:xxxx"),
          Accept: "application/json;odata=verbose"
      })
      .respond(200, { foo: 'bar' });
  
    $httpBackend.flush();
  
    expect($scope.valid).toBe(true);
    expect($scope.collection).toEqual({ foo: 'bar' });
  
  }));
  </code></pre>
  
  <p>I get this error,</p>
  
  <blockquote>
    <p>Error: Unexpected request: GET <a href="https://api.github.com/user/repos" rel="nofollow">https://api.github.com/user/repos</a> No
    more request expected</p>
  </blockquote>
  
  <p>Any ideas?</p>