我已经用 Angular 1.6.6、ng-mock 1.6.6、Jasmine 和 Karma 建立了一个测试环境。但即使是最简单的测试,我在尝试注入 deloreanApp 模块时也会得到 [$injector:modulerr]
由于以下原因无法实例化模块 deloreanApp:错误:[$injector:nomod]
理论上不存在错误,Angular 和 ng-mock 版本匹配。
我的文件是:
应用程序.js
(function () {
"use strict";
// initialize Angular
angular.module('deloreanApp', ['deloreanApp.controllers', 'deloreanApp.services']);
angular.module('deloreanApp.controllers', []);
angular.module('deloreanApp.services', []);
})();
控制器.js
(function () {
"use strict";
function deloreanController($scope){
$scope.sum = function(a,b){
return a + b;
}
}
angular.module('deloreanApp.controllers', []).controller('DeloreanController', ['$scope', deloreanController] );
})();
DeloreanController.test.js
describe('calculator', function () {
beforeEach(module('deloreanApp'));
var $controller;
beforeEach(inject(function (_$controller_) {
$controller = _$controller_;
}));
describe('sum', function () {
it('1 + 2 should equal 3', function () {
var result = 3;
expect(result).toBe(3);
});
});
});
我的karma.conf.js文件的一部分:
// list of files / patterns to load in the browser
files: [
'lib/angular.min.js',
'lib/angular-mocks.js',
'js/app.js',
'js/controllers.js',
'tests/DeloreanController.test.js'
],