title: Testing Angular Directives with their own controllers
body: <p>I'm attempting to write unit tests for an AngularJS directive that uses a separate controller from the one on the page. However, I can't find any way to access that controller from within my tests.</p>
  
  <p>Here's my directive:</p>
  
  <pre><code>'use strict';
  angular.module('myapp.directives')
    .directive('searchButton', function () {
      function SearchButtonCtrl ($scope, $location) {
        $scope.search = function () {
          $location.path('/search');
          $location.search(q, $scope.query.w);
        };
      }
      return {
        template: '&lt;input type="text" ng-model="query.q"&gt;',
        controller: SearchButtonCtrl,
        restrict: 'E'
      };
    });
  </code></pre>
  
  <p>Is it possible to access <code>SearchButtonCtrl</code>? Or is there a better way to structure my code such that it can be accessed?</p>