如何控制在karma config

时间:2015-09-12 02:09:52

标签: angularjs jasmine karma-runner

我正在使用Karma测试Angular应用程序。我已经完成了所有工作,但似乎我做错了什么。

https://gist.github.com/guyjacks/7bca850844deb612e681

如果我发表评论'app / notes / notes.main.js',Karma将抛出以下错误:

未捕获错误:[$ injector:nomod]模块'notes.main'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。   http://errors.angularjs.org/1.4.3/ $注射器/ NOMOD?P0 = notes.main   at /Users/guyjacks/projects/adr-demo/node_modules/angular/angular.js:1958

我不想手动列出每个应用程序文件来控制每个文件加载的顺序。我没有错,或者我只是按照我想要的顺序列出每个文件?

----基于接受答案的解决方案----

我的应用程序按照角度风格指南的推荐组织成模块:https://github.com/johnpapa/angular-styleguide

'app/app.module.js',
'app/**/*.module.js',
'app/**/*.service.js',
'app/**/*.controller.js',
'app/**/*.directive.js',
'app/**/*.js'

我认为上面不需要以下几行

'app/**/*.service.js', 
'app/**/*.controller.js',
'app/**/*.directive.js' 

当每个模块都有* .module.js文件中声明的角度模块时,就像我的应用程序一样。

那就是说,如果你确实需要在控制器和放大器之前显式加载服务。在指令之前的控制器然后这将是这样做的方式。

1 个答案:

答案 0 :(得分:0)

更新:我看不到您的业力档案,现在Gist链接已修复。

注释[。] main.js中的要点导致问题,

所以,' app / ** / *。js'不匹配notes.main.js。

现在尝试这样:app / ** / *。 *的.js

=============================================== ==============

更新前:

你必须在karma配置中加载你应用依赖的模块。档案:

module.exports = function(config) {
  config.set({

   .......

   // list of files / patterns to load in the browser
   files: [
    './client/app/vendors/angular/angular.js',

    // =====>  load Your modules here ...

    './client/app/app.js',
    './client/app/controllers/*.js',
    './client/app/directives/*.js',
    './client/app/services/*.js',
    './test/client/unit/**/*.js'
],
.....

}) }