"错误:[$ injector:modulerr]无法实例化模块ng到期"同时运行业力测试跑步者

时间:2016-10-25 17:14:00

标签: angularjs unit-testing mocha karma-runner chai

我正在尝试为我的应用程序运行测试用例但是介于两者之间。它给出了以下错误 -

  

错误:[$ injector:modulerr]由于以下原因导致无法实例化模块ng:   TypeError:' undefined'不是一个对象(评估' Function.prototype.bind.apply')   .......   ......   {路径} /test/unit/generate-form-directive.js:24

测试文件是(generate-form-directive.js) -

describe("UNIT DIRECTIVE: generateForm", function () {
    "use strict";

    // Angular injectables
    var $compile, $rootScope, $httpBackend;

    // Module defined (non-Angular) injectables
    var $scope, directiveScope, pagerVm;

    // Local variables used for testing
    var template;

    // Initialize modules
    beforeEach(function () {
        module("TestDataModule");
    });

    beforeEach(function () {
        inject(function (_$compile_, _$rootScope_, _$httpBackend_) {
            $compile = _$compile_;
            $rootScope = _$rootScope_;
            $httpBackend = _$httpBackend_;
        });   //Line no 24
    });

    it("test message", function() {
        console.log("Hello");
    });
});

我的Karma文件(karma.conf.js) -

module.exports = function (config) {
    config.set({
        basePath: "",
        frameworks: ["mocha", "chai", "sinon"],
        files: [

            "node_modules/angular/angular.js",
            "node_modules/angular-mocks/angular-mocks.js",

            // Add template files
            "src/**/*.html",

            "src/commons/js/*.js",
            "src/commons/services/*.js",
            "src/commons/directives/**/*.js",
            "src/modules/**/*.js",

            // Add all the test files
            "test/unit/*.js",
        ],

        exclude: [],

        preprocessors: {
            "src/**/*.js": "coverage"
        },

        reporters: ["mocha", "coverage"],
        mochaReporter: {
            // full, autowatch, minimal
            output: "autowatch",
            ignoreSkipped: false
        },

        browserNoActivityTimeout: 20000,
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ["PhantomJS"],
        singleRun: true,
        coverageReporter: {
            dir: "./coverage",
            reporters: [{
                type: "cobertura",
                subdir: ".",
                file: "cobertura.xml"
            }, {
                type: "text"
            }]
        }
    });
};

提前致谢。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。 minimatch模式(' / ** / *')在karma.conf.js中无效。

您有两种选择:

1)尝试更改您的minimatch版本并查看它是否有帮助。

2)或者指定每个文件而不是使用minimatch模式(" / ** / * .js")。

更改karma配置文件,如下所示:

        // Add template files
        "src/views/view1.html",
        "src/views/view2.html",

        "src/commons/js/myJs1.js",
        "src/commons/services/service1.js",
        "src/commons/services/service2.js",
        "src/commons/directives/directive1.js",
        "src/modules/moduleName/moduleNAme1.js",

        // Add all the test files
        "test/unit/testFile1.js",