【发布时间】:2014-03-07 23:25:28
【问题描述】:
我的 Angular 应用运行良好,我的测试也运行良好,使用 karma 和 jasmine,直到我在 ui.bootstrap 中添加了一个依赖项。现在该应用程序仍按预期工作,但我无法运行我的测试。这就是我所拥有的:
app.js - 在 ui.bootstrap
中添加了依赖项angular.module('myApp', ['ngResource', 'ngRoute', 'ui.bootstrap']).config(function(...) {...});
service.js
angular.module('myApp').service('myService', function () {})
controller.js
angular.module('myApp').controller('MyController', function ($scope, $http, myService) {})
tests/main.js
describe('Controller: MyController', function () {
var MyController, scope;
// load the controller's module
beforeEach(function(){
module('myApp');
inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
MyController = $controller('MyController', {
$scope:scope
});
});
});
it('should do something', function () {
expect(scope.myOptions.length).toBe(5);
});
});
我使用 grunt 和 krama 运行的测试失败,原因是:
Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module ui.bootstrap due to:
Error: [$injector:nomod] Module 'ui.bootstrap' is not available! You either misspelled the module name or forgot
我错过了什么?应用程序运行没有问题,只有测试失败。
【问题讨论】:
-
请检查您的 karam.conf.js 文件是否包含 bootstrap-ui js 文件。
-
是的,就是这样。错过了那里的 karma.conf.js。谢谢!
-
我刚才也遇到了同样的问题,但我想知道如果它是一个单元测试,为什么我应该加载所有模块并且应该隔离那段特定的代码?除非我误解了,否则感觉就像您必须加载更像是集成测试的所有内容?
标签: javascript angularjs jasmine angular-ui-bootstrap karma-jasmine