在进行AngularJS应用程序单元测试时无法注入依赖项ngComboDatePicker

时间:2018-01-17 10:22:29

标签: angularjs jasmine karma-jasmine

Angular模块定义如下:

angular.module('app', ['ngComboDatePicker']);

控制器文件:

angular.module('app')

.controller('pricebreakdown', ["$scope", "$rootScope", "$stateParams", "$log", "$q",

    function($scope, $rootScope, $stateParams, $log, $q) {
        $scope.coolVariable = "pricebreakdown-view";
        $scope.coolMethod = function(){
            $log.log("This is a sample method");
        };
    }
]);

规范文件:

describe('Unit: pricebreakdown', function() {

    beforeEach(module('app'));

    var ctrl, scope, rootScope, stateParams, log, q;

    beforeEach(inject(function($controller, $rootScope) {
        scope = $rootScope.$new();
        ctrl = $controller('pricebreakdown', {
            $scope: scope,
            $rootScope: rootScope,
            $stateParams: stateParams,
            $log: log,
            $q: q
        });

    }));

    it('this is the sample test', function() {
        expect($scope.coolVariable).toBe('pricebreakdown-view');
    });
})

配置文件如下所示:

files: [  'bower_components/angular/angular.js',

          'bower_components/angular-mocks/angular-mocks.js',
          'bower_components/angular-ui-router/release/angular-ui-router.min.js',
          'bower_components/jquery/dist/jquery.min.js',
          'bower_components/angular-bootstrap/ui-bootstrap.min.js',
          //'src/**/*.js',
          //'src/**/*.html',
          //'test/**/*.js',
          'src/app/app.js',
          'src/app/booking/payment-confirm/price-breakdown/pricebreakdown.controller.js',
          'test/app/booking/paymentconfirm/pricebreakdown/pricebreakdown.spec.js'
        ],

来自CMD的错误是:

Error: [$injector:modulerr] Failed to instantiate module budget.app due to:
        Error: [$injector:modulerr] Failed to instantiate module ngComboDatePicker due to:
        Error: [$injector:nomod] Module 'ngComboDatePicker' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Chrome 63.0.3239 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.044 secs / 0.017 secs).

帮我这个?如何注入这些依赖?

0 个答案:

没有答案