title: Mocking $state change in AngularJS controller
body: <p>Main module being injected with everything;</p>
  
  <pre><code>require('./dashboard');
  module.exports = angular.module('college', ['college.dashboard'])
  
      .config(function ($stateProvider) {
          $stateProvider
              .state('college.list', {
                  url: '/college',
                  templateUrl: '/dashboard/dashboard.html',
                  controller: 'DashboardCtrl',
                  authenticate: true
              });
      })
      .factory('ProjectFactory', require('./services/college.service'));        
  </code></pre>
  
  <p>College Index, which makes the dashboard controller available;</p>
  
  <pre><code>module.exports = angular.module('college.dashboard', 
    [])
      .controller('DashboardCtrl', require('./dashboard.controller.js'));
  </code></pre>
  
  <p>The college controller exposes the following method;</p>
  
  <pre><code>    module.exports = function($scope, $rootScope, $state) {
  
           $scope.openCollege = function(id) {       
              $rootScope.currentCollege = id;
              $state.go('college.main', {currentCollege: id});
          };
     };
  </code></pre>
  
  <p>The following error is thrown when the unit test calls </p>
  
  <pre><code>scope.openCollege (2);
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> Error: Could not resolve 'college.main' from state ''
  </code></pre>
  
  <p>Creating state;</p>
  
  <pre><code>beforeEach(inject(function ($rootScope, $state, $location, $controller) {
          scope = $rootScope.$new();
          location = $location;
          rootScope = $rootScope;
          $rootScope.currentCollege = {};// Empty by default
          state = $state;            
  
          $controller('DashboardCtrl', {
              $scope: scope,
              $state: state,
              $location: location
          });
  
      }));
  </code></pre>
  
  <p>Some of the spec test code;</p>
  
  <pre><code> expect(state.current.name).to.equal('');
   scope.openCollege(2);
  </code></pre>
  
  <p>I need to figure out how to handle/mock <em>$state.go</em> during the Karma unit testing so that state knows about college.main.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>J</p>