"Error: [$injector:modulerr] Failed to instantiate module ng due" 在运行业力测试运行器时



我正试图为我的应用程序运行测试用例,但卡在两者之间。它给出以下错误-

错误:[$injector:modulerr]实例化ng模块失败,原因如下:TypeError: 'undefined'不是对象(求值'Function.prototype.bind.apply')…………{path}/测试/单位/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"
            }]
        }
    });
};

我也遇到了同样的问题。最小匹配模式('/**/*')在karma.conf.js中不起作用。

你有两个选择:

1)试着改变你的小匹配版本,看看是否有帮助。

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",

相关内容

最新更新