AngularJS Jasmine测试失败:无法实例化模块

Haj*_*aji 22 javascript jasmine angularjs angular-ui-bootstrap karma-jasmine

我的角度应用程序工作得很好,我的测试也是如此,使用了业力和茉莉,直到我添加了一个依赖ui.bootstrap.现在应用程序仍然按预期工作,但我无法运行我的测试.这就是我所拥有的:

app.js - 在ui.bootstrap中添加了依赖

angular.module('myApp', ['ngResource', 'ngRoute', 'ui.bootstrap']).config(function(...) {...});
Run Code Online (Sandbox Code Playgroud)

service.js

angular.module('myApp').service('myService', function () {})
Run Code Online (Sandbox Code Playgroud)

controller.js

angular.module('myApp').controller('MyController', function ($scope, $http, myService) {})
Run Code Online (Sandbox Code Playgroud)

测试/ 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);
    });
}); 
Run Code Online (Sandbox Code Playgroud)

我使用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
Run Code Online (Sandbox Code Playgroud)

我错过了什么?应用程序运行没有问题,只有测试失败.

Bas*_*igt 35

karma.conf.js测试执行之前,有一个karma加载的文件列表:

// list of files / patterns to load in the browser
files: [
  'bower_components/angular/angular.js',
  'bower_components/angular-mocks/angular-mocks.js',
  ...
]
Run Code Online (Sandbox Code Playgroud)

在那里添加bootstrap-ui.js.

  • 问题:你不必做这样的事吗?`module('myApp',['ngResource','ngRoute','ui.bootstrap'])``在测试中引用和实现模块? (4认同)