title: Unit testing controller which uses $state.transitionTo
body: <p>within a controller i have a function which uses <code>$state.transitionTo</code> to "redirect" to another state.</p>
  
  <p>now i am stuck in testing this function, i get always the error <code>Error: No such state 'state-two'</code>. how can i test this? it its totally clear to me that the controller does not know anything about the other states, but how can i mock this state? </p>
  
  <p>some code:</p>
  
  <hr>
  
  <pre><code>angular.module( 'mymodule.state-one', [
    'ui.state'
  ])
  
  .config(function config($stateProvider) {
    $stateProvider.state('state-one', {
      url: '/state-one',
      views: {
        'main': {
          controller: 'MyCtrl',
          templateUrl: 'mytemplate.tpl.html'
        }
      }
    });
  })
  
  .controller('MyCtrl',
    function ($scope, $state) {
      $scope.testVar = false;
      $scope.myFunc = function () {
        $scope.testVar = true;
        $state.transitionTo('state-two');
      };
  
    }
  );
  </code></pre>
  
  <hr>
  
  <pre><code>describe('- mymodule.state-one', function () {
  
    var MyCtrl, scope
  
    beforeEach(module('mymodule.state-one'));
  
    beforeEach(inject(function ($rootScope, $controller) {
  
      scope = $rootScope.$new();
  
      MyCtrl = $controller('MyCtrl', {
        $scope: scope
      });
  
    }));
  
    describe('- myFunc function', function () {
      it('- should be a function', function () {
        expect(typeof scope.myFunc).toBe('function');
      });
  
      it('- should test scope.testVar to true', function () {
        scope.myFunc();
        expect(scope.testVar).toBe(true);
        expect(scope.testVar).not.toBe(false);
      });
    });
  });
  </code></pre>