title: Using $httpBackend in a service whilst testing an Angular controller
body: <p>I'm trying to test a controller in my Angular framework:</p>
  
  <pre><code>.controller('UserCtrl', ['$scope', '$location', 'User', 'Config',
      function ($scope, $location, User, Config) {
         ...
      }])
  </code></pre>
  
  <p>This controller depends on a couple of Services that require the $http object to make server calls:</p>
  
  <pre><code>.factory('User', ['$http', function ($http) {
      var data = {};
  
      return {
          query: function(oper, putdata, callback){
              if(oper == 'get'){
              $http.get(getUrl("user",null)).success(function(data2) {
                  console.log(data2);
  
                  callback(data2);
                  data.userinfo = data2;
              });
              },
  
          userinfo: data
      };
  }])
  </code></pre>
  
  <p>But when I try bootstrapping the controller I can't get httpBackend to work:</p>
  
  <pre><code>describe('UserCtrl', function(){
  
      var ctrlScope, ctrl, $httpBackend, controllerService;
  
      beforeEach(
          inject(function($httpBackend, $http, $rootScope, $controller, User, Config) {
              _User = User;
              _Config = Config;
              spyOn(User, 'getUserInfo').andCallThrough();
              //spyOn(User, 'query').andCallThrough();
  
              ctrlScope = $rootScope.$new();
              controllerService = $controller;
              httpMock = $httpBackend;
  
          })
      );
  
      it('should create setup userinfo object ', function() {
          httpMock.expectGET("/user/default/details").
              respond({somejson});
  
          ctrl = controllerService('UserCtrl', {$scope: ctrlScope, $location: location, User: _User, Config: _Config});
          expect(_User.getUserInfo).toHaveBeenCalled();
          httpMock.flush();
          expect(ctrlScope.userinfo.length).toBe(1);
  
      });
  });
  </code></pre>
  
  <p>All I ever get is:</p>
  
  <pre><code>Error: No pending request to flush !
  </code></pre>
  
  <p>so is it possible to use httpBackend with a service that you have called from a controller you are testing?</p>