[英]AngularJS Unit Test Error dependence
I create a very small project to test the unit test in AngularJS . 我创建了一个非常小的项目来测试AngularJS中的单元测试 。 The test work until I try to include the dependence restangular .
测试工作直到我尝试将依赖关系矩形包括在内 。 Why it generates conflicts ?.
为什么会产生冲突 ? Files:
档案:
karma.conf.js karma.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 app.js
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'ngCookies',
'angular-md5',
'restangular' //This generate ERROR!
]);
app.spec.js 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);
}));
When you trying to load restangular. 当您尝试加载矩形时。 Then you might be getting error like Faild to instantiate module restangular due to
(_'underscore.js')
is undefined. 然后,您可能会收到错误消息,例如由于未定义
(_'underscore.js')
而无法实例化模块的矩形。 The '_'(undescore)
javascript utility library that Restangular uses and depending on it. Restangular使用并取决于它的
'_'(undescore)
undescore '_'(undescore)
javascript实用程序库。 Include (_'underscore.js')
library before the angular js in your template. 在模板中的有角js之前包含
(_'underscore.js')
库。
Here is your working jsfiddle code please take a look http://jsfiddle.net/chhitij92/x67u4Ldu/ In external resource I Included '_'(undescore)
cdn after this its working. 这是您正在工作的jsfiddle代码,请看一下http://jsfiddle.net/chhitij92/x67u4Ldu/。在此工作之后,我在外部资源中包含了
'_'(undescore)
undescore '_'(undescore)
cdn 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.