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(){
});
});
我的问题是: