title: How to mock the Controller of an AngularJS Directive
body: <p>Given a directive that has an external controller:</p>
  
  <pre><code>.directive('d1', function () {
    return {
      controller: 'd1controller',
      restrict: 'E',
      link: function ($scope, $element, $attributes, $controller) {
  
        $controller.doStuff();
  
      }
    };
  });
  </code></pre>
  
  <p><strong>How do I mock the <code>d1controller</code> controller in the <code>d1</code> directive's unit tests?</strong></p>
  
  <hr>
  
  <p>My attempts:</p>
  
  <p>I tried with <code>$provide</code> as when mocking a service:</p>
  
  <pre><code>  beforeEach(module('app', function ($provide) {
      ctrlMock = jasmine.createSpyObj('ctrlMock', ['doStuff']);
      $provide.value('d1controller', ctrlMock );
    }));
  </code></pre>
  
  <p>And I also tried with <code>$controllerProvider</code></p>
  
  <pre><code>  beforeEach(module('app', function ($controllerProvider) {
      ctrlMock = jasmine.createSpyObj('ctrlMock', ['doStuff']);
      $controllerProvider.register('d1controller', ctrlMock);
    }));
  </code></pre>