title: Why is $provide only available in the 'angular.mock.module' function, and $q only available in the 'angular.mock.inject' function?
body: <p>I am mocking out a service for an AngularJS Unit Test. I'm using the <code>$provide</code> service to replace the 'real' service with the mocked out one (a <a href="http://plnkr.co/edit/1Gbr1N?p=preview" rel="noreferrer">plunker script</a> of this is available):</p>
  
  <pre><code>describe('My Controller', function () {
  
      var $scope;
      var $provide;
  
      beforeEach(angular.mock.module('myApp'));
  
      beforeEach(angular.mock.module(function (_$provide_) {
  
          $provide = _$provide_;
  
      }));
  
      beforeEach(angular.mock.inject(function($rootScope, $controller, $q){
  
          var mockMyService = {
              getAll : function() {
                  var deferred = $q.defer();
                  deferred.resolve([
              { itemText: "Foo" },
              { itemText: "Bar" }
                  ]);
  
                  return deferred.promise;
              }
          };
  
          $provide.value('myService', mockMyService);
  
          $scope = $rootScope.$new();
  
          $controller('MyCtrl', { $scope: $scope });
  
          $rootScope.$apply();
  
      }));
  
      it('Has two items defined', function () {
          expect($scope.items.length).toEqual(2);
      });
  });
  </code></pre>
  
  <p>This works just fine. However, I don't like the fact that I am using an <code>angular.mock.module</code> function simply to give a reference to the <code>$provide</code> service which is then used in the <code>angular.mock.inject</code> function below. But if I add <code>$provide</code> as a parameter to the <code>angular.mock.inject</code> function directly instead, I get an 'unknown provider' error.</p>
  
  <p>It occurs to me that I could put all the mocking code in the <code>angular.mock.module</code> function. But then I have a similar issue with the <code>$q</code> reference, which I need as my mocked service has to return a promise.</p>
  
  <p>In other words, if I add a <code>$q</code> parameter to the <code>angular.mock.module</code> function then I also get an 'unknown provider' error.</p>
  
  <p>Is there a way to simplify this? Obviously what I have works but it doesn't feel quite right, somehow. I feel that I lack understanding of why some providers are available in <code>inject</code> functions and others are available in <code>module</code> functions.</p>