有一些麻烦。我在解决方案中找到了类似的问题,但它对我没有帮助。
首先,我想测试我的角度脚本。
var app = angular.module('app', ['ngRoute']);
app.factory('settingsFactory', ['$http',
function($http) {
//factory logic here
}
]);
app.controller('settingsCtrl', ['$scope', 'settingsFactory',
function($scope, settingsFactory) {
//controller logic here
}
]);
我的测试
describe('Settings Controller', function() {
var controller, scope, factory;
beforeEach(function() {
module('app');
});
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
factory = $injector.get('settingsFactory');
controller = $controller('settingsCtrl', {
$scope: scope,
settingsFactory: factory
});
}));
describe('Test inject', function () {
it("this dummy checks injecting of settings controller", function () {
expect(controller).toBeDefined();
});
});
});
我的测试失败错误:[$ injector:modulerr]。
修复我的大脑,伙计们。我不知道会发生什么。
添加SpecRunner.html。假设我忘了包含一些东西......
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jasmine Spec Runner v2.0.0</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="../angular.min.js"></script>
<script type="text/javascript" src="../angular-route.min.js"></script>
<script type="text/javascript" src="../angular-mocks.js"></script>
<script type="text/javascript" src="../app/app.js"></script>
<script type="text/javascript" src="../app/controllers/settingsCtrl.js"></script>
<script type="text/javascript" src="../app/services/settingsFactory.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/hello-world-spec.js"></script>
<script type="text/javascript" src="spec/controllers/settings-ctrl-spec.js"></script>
</head>
<body>
</body>
</html>
2014 \ 03 \ 07
使用相同版本的angular.js - v.1.2.5添加angular-mocks.js并收到此错误: 无法读取未定义的属性“正在运行”
答案 0 :(得分:1)
我已经喝了一些啤酒并删除了angular.min.js,angular-mocks.js并下载了这些角度的稳定v1.2.14。这很好。
只使用一个(稳定)版角度,只喝深色啤酒!
答案 1 :(得分:0)
你的函数参数中是否有可能缺少$ injector,所以代替:
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
factory = $injector.get('settingsFactory');
使用:
beforeEach(inject(function($controller, $rootScope, $injector) {
scope = $rootScope.$new();
factory = $injector.get('settingsFactory');