【发布时间】:2015-05-26 05:52:11
【问题描述】:
尝试为我的控制器编写单元测试:
app.controller('StartGameCtrl', function ($scope, $timeout,$state) {
$scope.startGame = function () {
$scope.snap = false;
$scope.dealCards();
debugger;
$state.go('cpu');
}
});
我写了这个 jasmine 单元测试:
describe('snap tests', function() {
beforeEach(module('snapApp'));
var scope, createController, state;
beforeEach(inject(function ($rootScope, $controller,$state) {
scope = $rootScope.$new();
createController = function () {
return $controller('StartGameCtrl', {
'$scope':scope,
'$state':state
});
};
}));
it('startGame should call dealcards', function () {
var controller = createController();
spyOn(scope, 'dealCards');
scope.startGame();
//expect(scope.dealCards).toHaveBeenCalled();
});
});
当我运行我的业力测试时,我得到一个错误:
TypeError: 'undefined' is not an object (evaluating '$state.go')
at startgamectrl.js:9
【问题讨论】:
-
您的
snapApp模块中是否包含ui.router模块?
标签: angularjs unit-testing angular-ui-router karma-jasmine