我创建了一个非常小的项目来测试AngularJS中的单元测试。测试一直在进行,直到我尝试包含依赖性restangular。为什么它会生成冲突?。文件:
因果报应.conf.js
files: [
'lib/angular.js',
'lib/angular-route.js',
'lib/angular-mocks.js',
'lib/angular-cookies.js',
'lib/angular-md5.js',
'lib/restangular.js',
'app.js',
'tests/app.spec.js'
]
app.js
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'ngCookies',
'angular-md5',
'restangular' //This generate ERROR!
]);
app.spec.js
describe('PhoneListController', function() {
beforeEach(module('phonecatApp'));
beforeEach(module('ngRoute'));
beforeEach(module('angular-md5'));
beforeEach(module('restangular')); //This generate ERROR!
it('should...', inject(function($controller) {
var scope = {};
var ctrl = $controller('PhoneListController', {$scope: scope});
expect(scope.phones.length).toBe(3);
}));
当您尝试加载restangular时。那么你可能会犯这样的错误由于未定义(_'underscore.js')
,无法实例化模块restangular。Restangular使用的'_'(undescore)
javascript实用程序库,并依赖于它。在模板中的angular js之前包含(_'underscore.js')
库。
这是您的工作jsfiddle代码,请看一下http://jsfiddle.net/chhitij92/x67u4Ldu/在外部资源中,我包含了'_'(undescore)
cdn,之后它就工作了。