未知提供者:$ angularFileUploadProvider< - $ jamine angular test中的angularFileUpload

时间:2015-03-13 16:06:52

标签: angularjs jasmine karma-jasmine

我对我的角度模块有一个指令,我正在尝试编写测试。首先,我不清楚如何正确测试这个指令,但此时,当业力运行测试时,我得到以下错误。

Unknown provider: $angularFileUploadProvider <- $angularFileUpload

这是我的考验。

describe('Testing onlyDigits directive', function(){

    var elm, scope;

    beforeEach(module('jobBoard'))

    beforeEach(inject(function($route, $filter, $angularFileUpload, $animate, $rootScope, $compile) {
        elm = angular.element('<input id="testinput" type="number" onlyDigits />');
        scope = $rootScope;
        $compile(elm)(scope);
        scope.$digest();
    }));

    it('should limit input to numbers and decimal', function(){

    })
})

这是我的指令模块......

angular.module('jobBoard', ['ngRoute', 'jobFilters', 'angularFileUpload','ngAnimate'])
    .config(['$routeProvider', '$locationProvider','$sceDelegateProvider', 'templates', function($routeProvider, $locationProvider, $sceDelegateProvider, templates){
        //routes ommitted for brevity
    }
]).directive('onlyDigits', function () {
    return {
        restrict: 'A',
        require: '?ngModel',
        link: function (scope, element, attrs, ngModel) {
            if (!ngModel) return;
            ngModel.$parsers.unshift(function (inputValue) {
                var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' ' || s == '.'); }).join('');
                ngModel.$viewValue = digits;
                ngModel.$render();
                return digits;
            });
        }
    };
});

这是我的业力配置文件

module.exports = function(config){
  config.set({

    basePath : './',

    files : [
      'vendor/assets/javascripts/angular/angular.js',
      'vendor/assets/javascripts/angular-route/angular-route.js',
      'vendor/assets/javascripts/angular-animate/angular-animate.js',
      'vendor/assets/javascripts/ng-file-upload-shim/angular-file-upload.js',
      'vendor/assets/javascripts/ng-file-upload/angular-file-upload.js',
      'vendor/assets/javascripts/angular-mocks/angular-mocks.js',
      'app/assets/javascripts/components/**/*.js',
      'app/assets/javascripts/view*/**/*.js',
      'spec/javascripts/**/*_spec.js'
    ],

    autoWatch : true,

    frameworks: ['jasmine'],

    browsers : ['Chrome'],

    plugins : [
            'karma-chrome-launcher',
            'karma-firefox-launcher',
            'karma-jasmine',
            'karma-junit-reporter'
            ],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    }

  });
};

1 个答案:

答案 0 :(得分:0)

您正在茉莉花beforeEach设置中注入大量服务:

beforeEach(inject(function($route, $filter, $angularFileUpload, $animate, $rootScope, $compile) {
    // ...
}

您应该只在[{1}}函数中注入您实际使用的服务:beforeEach$rootScope

$compile

特别是您尝试注入的beforeEach(inject(function($compile, $rootScope) { // ... }); 服务未在加载的任何模块中定义:$angularFileUpload'jobBoard'