2016-03-02 66 views
0

我刚刚开始使用Karma设置一些测试。我使用jdDom进行了一些测试,但不喜欢它如何配置。但是,我不知道如何正确指向js文件。正如我收到此错误Karma角度测试未能实例化模块

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/modules/utility/module.utility.built.js');

这些脚本是我的模块驻留的地方。我不确定将它们放入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 

基本上我需要这些测试来找到模块​​。

回答

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' 

], 
+0

好有意义把它在文件中。理想情况下,我会把我的测试之前正确的? – Winnemucca

+0

正确。对于我的Karma测试,我首先拥有了所有的.js依赖关系,然后是我的控制器和指令,然后是主app.module.js,然后是测试。 –

+0

这个问题在ng2Html预处理器中是否可行?当我启动预处理器并指向Templates文件夹时,我重新发生了此错误 – Winnemucca