컨트롤러 단위 테스트 방법에 대한 각도 튜토리얼을 따르고 있습니다. 나는 테스트를 위해 카르마와 재스민을 사용하고 있습니다. 테스트를 실행할 때단위 Angular.js에서 컨트롤러 테스트
Error: [ng:areq] Argument 'testController' is not a function, got undefined
test.js에서 testController를로드하는 방법에 대한 아이디어가 있습니까? 아래 코드. 감사!
<!-- app.js -->
var simulatorApp = angular.module('simulatorApp', ['ngRoute', 'ngResource', 'ngCookies'],
simulatorApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {templateUrl: '/angular/views/home.html', controller: homeController})
.when('/test', {templateUrl: '/angular/views/test.html', controller: testController})
.otherwise({redirectTo: '/'});
}]);
<!-- testController.js -->
function testController($scope) {
$scope.password = '';
$scope.grade = function() {
var size = $scope.password.length;
if (size > 8) {
$scope.strength = 'strong';
} else if (size > 3) {
$scope.strength = 'medium';
} else {
$scope.strength = 'weak';
}
};
}
<!-- test.js -->
describe('testController', function() {
beforeEach(module('simulatorApp'));
var $controller;
beforeEach(inject(function (_$controller_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));
describe('$scope.grade', function() {
it('sets the strength to "strong" if the password length is >8 chars', function() {
var $scope = {};
var controller = $controller('testController', {$scope: $scope});
$scope.password = 'longerthaneightchars';
$scope.grade();
expect($scope.strength).toEqual('strong');
});
});
})
$ routeProvider에서 컨트롤러를 문자열로 참조해야했습니다. 감사! –