Angularjs 基于state.params编写jasmine测试

Angularjs 基于state.params编写jasmine测试,angularjs,jasmine,Angularjs,Jasmine,我的控制器如下所示: function Ctrl1($scope,$state, $modal, $q, ResourceABC) { function1(){ /*.. something happens here.*/} function2(){ /*.. something happens here .*/} function3(){ /*.. something happens here.*/} if (!$state.params.gameID) { var

我的控制器如下所示:

function Ctrl1($scope,$state, $modal, $q, ResourceABC) {

  function1(){ /*..   something happens here.*/}
  function2(){ /*.. something happens here .*/}
  function3(){ /*.. something happens here.*/}

if (!$state.params.gameID) {
    var singleGameID = 'tmp-xyz';
    var multipleGameID = 'gen-abc';    

    if ($state.current.name === 'single-user') {
      $scope.player.gameID = singleGameID;
    }    
    else if ($state.current.name === 'multi-user') {
      $scope.player.gameID = multipleGameID;
    }    
    else {
      $scope.player.gameID = singleGameID;
    }

  }
  else {
    $scope.player.gameID = $state.params.gameID;
}

}
我编写了测试代码,如下所示:

describe('Ctrl1',function(){

  var $rootScope,$controller,$httpBackend,q,state;

  beforeEach(module(game));

  beforeEach(function(){

    angular.mock.inject(function($injector){
      $rootScope = $injector.get('$rootScope');
      $controller = $injector.get('$controller');      
      q = $injector.get('$q');
      state = $injector.get('$state');
    });

    var scope = $rootScope.$new();
    var resource1 = sinon.stub({});

    createController = function(){
      return $controller('DynamicRegistrationDialogCtrl',{
        $scope: scope,
        $state: state,        
        $q: q,
        ResourceABC: resource1       
      });
    }

  });

  it('should check that $scope.player.gameID is set',function(){

  });

});
我的问题是:

  • 当我只想测试控制器的一个小功能时,我是否必须在测试中创建$controller时加载所有依赖项

  • 其次,如何测试$scope.player.gameID的设置?我的意思是我如何通过$state.parmams。 这里的行动是什么