我正在使用Angularjs和Jasmine。
我收到以下错误:
Error: [$injector:modulerr] Failed to instantiate module myApplication due to:
Error: [$injector:nomod] Module 'myApplication' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.4/$injector/nomod?p0=myApplication
at file:///Users/Documents/angularjs/code/src/lib/scripts/1_4_4/angular.js:68:12
...
TypeError: Cannot read property 'amount' of undefined
at UserContext.<anonymous> (file:///Users/Documents/angularjs/code/spec/tests/index_09_controller.spec.js:13:23)
MY-template.html
<html ng-app="myApplication">
<head>
<script src="lib/scripts/1_4_4/angular.min.js"></script>
</head>
<body>
<div ng-controller="SimpleController">
{{amount.length}}
</div>
<script>
var myModule = angular.module('myApplication', []);
myModule.controller('SimpleController', function($scope) {
$scope.amount = ['a','b','c'];
});
</script>
</body>
</html>
MY-template.spec.js
describe('a simple controller', function(){
var $scope;
//See API angular.mock.module
beforeEach(module('myApplication'));
beforeEach( inject( function( $rootScope, $controller ){
$scope = $rootScope.$new();
$controller('SimpleController',{$scope : $scope});
}));
it('test scope amount', function(){
expect($scope.amount.length).toBe(3);
});
});
SpecRunner.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.8.0</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.8.0/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.8.0/jasmine.css">
<script src="lib/jasmine-2.8.0/jasmine.js"></script>
<script src="lib/jasmine-2.8.0/jasmine-html.js"></script>
<script src="lib/jasmine-2.8.0/boot.js"></script>
<script src="src/lib/scripts/1_4_4/angular.js"></script>
<script src="src/lib/scripts/1_4_4/angular-mocks.js"></script>
<!-- include source files here... -->
<script src="src/my-template.html"></script>
<!-- include spec files here... -->
<script src="spec/tests/my-template.spec.js"></script>
</head>
<body>
</body>
</html>
我错过了什么?
放弃此行
[我只是要在下面添加一些乱码,所以stackoverflow赢得了错误,说没有足够的描述:&#34; Lorem ipsum dolor坐下来,精神上的adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。 Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat。 Duis aute irure dolor in repreptderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。 Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum。&#34;]
答案 0 :(得分:2)
想出来。我不得不从html中删除脚本并制作一个单独的.js文件。
MY-template.js
var myModule = angular.module('myApplication', []);
myModule.controller('SimpleController', function($scope) {
$scope.amount = ['a','b','c'];
});
MY-template.html
<html ng-app="myApplication">
<head>
<script src="lib/scripts/1_4_4/angular.min.js"></script>
<script src="my-template.js"></script>
</head>
<body>
<div ng-controller="SimpleController as ctrl">
{{amount.length}}
</div>
</body>
</html>
SpecRunner.html - 添加以下行
...
<script src="src/my-template.js"></script>
...
答案 1 :(得分:0)
通过右键单击gulpfile.js手动重新运行gulp
gulpfile.js -> Task runner Explorer -> Right click Clean -> Run ...
对“默认和构建”子菜单进行相同的设置。