我正在使用最新的 Karma Angular.js 单元测试。
我遇到错误:“参数“appCtrl”不是函数,未定义”。
appCtrl.js:
var app = angular.module('app', []);
app.controller('appCtrl', function ($scope) {
$scope.count = 5;
$scope.incrementCount = function() {
$scope.count = $scope.count + 1;
};
});
appCtrl.spec.js:
describe('Controller test', function(){
var appCtrl, $scope;
beforeEach(module('app'));
beforeEach(inject(function($controller, $rootScope) {
$scope = $rootScope.$new();
appCtrl = $controller('appCtrl', {
$scope: $scope
});
}));
it('should have appCtrl controller toBeDefined', function() {
expect(appCtrl).toBeDefined();
});
iit('should init counter value', function() {
expect($scope.count).toBeDefined();
expect($scope.count).toBe(5);
});
it('should change counter value', function() {
$scope.incrementCount();
expect($scope.count).toBe(6);
});
});
我做错了什么?
最佳答案
确保您具有 Angular-Mocks 依赖项,并且在 should init 计数器值中存在拼写错误“itt”应该是“it”。
希望这有帮助。
关于angularjs - 参数 'appCtrl' 不是函数,未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24481283/