Kontroler testów jednostkowych, który używa $ state.transitionTo

w kontrolerze mam funkcję, która używa$state.transitionTo „przekierować” do innego stanu.

teraz utknąłem w testowaniu tej funkcji, zawsze otrzymuję błądError: No such state 'state-two'. jak mogę to przetestować? jest dla mnie całkowicie jasne, że kontroler nie wie nic o innych stanach, ale jak mogę kpić z tego stanu?

jakiś kod:

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');
    };

  }
);
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);
    });
  });
});

questionAnswers(3)

yourAnswerToTheQuestion