Karma角度测试无法实例化模块

时间:2016-03-02 20:28:15

标签: karma-runner karma-jasmine

我刚刚开始用Karma设置一些测试。我使用jdDom进行了一些测试,但不喜欢它的配置方式。但是,我不确定如何正确指向js文件。因为我收到此错误

 Error: [$injector:modulerr] Failed to instantiate module ha.module.utility due to:
    Error: [$injector:nomod] Module 'ha.module.utility' 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.

我用jsdom创建了一个需要核心模块的文件

要求(” ../../../ SRC /模块/核心/ module.core.built.js');    要求(” ../../../ SRC /模块/效用/ module.utility.built.js');

这些脚本是我的模块所在的位置。我不知道把它们放在karma文件中的哪个位置。 或者如果这是问题。这是我的karma文件。我删除了karma init附带的评论,因此可以更快地阅读这篇文章。

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: 'Scripts/',

frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
    'jquery /jquery libraries ',
    '../node_modules/angular/angular.js',
    '../node_modules/angular-mocks/angular-mocks.js',
    'test2/*.js',
    'tests/**/*.js'

],
exclude: [
    'tests/old/**',
    'tests/**/*.setup.js'
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
    '../Templates/**/*.html' : ['ng-html2js']
},

ngHtml2JsPreprocessor: {
        // setting this option will create only a single module that contains templates
        // from all the files, so you can load them all with  angular.mock.module('foo')

        //stripPrefix: "Templates/",
        //prependPrefix: "Templates/",
        moduleName: 'templates'
    },

// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


port: 9876,

colors: true,


logLevel: config.LOG_INFO,


autoWatch: true,



browsers: ['Chrome'],

singleRun: true,

concurrency: Infinity 

基本上我需要这些测试才能找到模块。

1 个答案:

答案 0 :(得分:3)

你的模块'指令,控制器和所有其他必需文件应上传到您的文件列表中,"像这样:

files: [
    '../node_modules/angular/angular.js',
    '../node_modules/angular-mocks/angular-mocks.js',
    '../../../src/modules/core/module.core.built.js',
    '../../../src/modules/utility/module.utility.built.js',
    'test2/*.js',
    'tests/**/*.js'

],