2016-03-02 65 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