Karma抱怨'模块不可用'

spa*_*guy 12 javascript angularjs karma-runner

直到几天前我的单元测试运行良好,我的代码在浏览器中完美运行.然后我添加了一个名为'profile'的存根模块后注意到了这一点:

INFO [karma]: Karma v0.12.24 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket 7W-0vnkWZaWxYYtwFrhT with id 9336780
PhantomJS 1.9.7 (Mac OS X) ERROR
  Error: [$injector:nomod] Module 'profile' 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.
Run Code Online (Sandbox Code Playgroud)

现在,我意识到这是世界上最常见的AngularJS错误,我已经很好地调试了这个,但是对于我的生活,我无法让它消失.细节:

  • 代码在浏览器中工作,没有错误.
  • Karma以这种方式获取我的文件:

        'node_modules/angular/angular.js',
        'node_modules/angular-mocks/angular-mocks.js',
        'node_modules/angular-ui-router/release/angular-ui-router.js',
        'node_modules/angular-bootstrap/ui-bootstrap.js',
        'node_modules/angular-ui-form-validation/dist/angular-ui-form-validation.js',
        'node_modules/angular-animate/angular-animate.js',
        'client/app/**/*.js'
    
    Run Code Online (Sandbox Code Playgroud)
  • 主模块依赖于已经声明的'profile'.

  • profile.js,profile.controller.js和profile.controller.spec.js是由cg-angular-fullstack生成的存根,没有特殊代码.默认情况下,生成器将它们全部放在主模块中,因此我将每个模块更改为"配置文件".

我完全没有想法.如果我无法调试这个,我将不得不假设我的整个应用程序设计存在缺陷并重新启动.:(

spa*_*guy 20

不知何故,Karma没有按照正确的顺序导入文件,即使它已经存在数周之前.我的决议分为三部分:

  1. 将所有模块定义从*.js重命名为*.module.js.
  2. 将所有不在模块定义中的UI路由器工作从*.js重命名为*.state.js.
  3. 按此顺序导入的文件:

          'node_modules/jquery/dist/jquery.js',
          'node_modules/angular/angular.js',
          'node_modules/angular-mocks/angular-mocks.js',
          'node_modules/angular-ui-router/release/angular-ui-router.js',
          'node_modules/angular-bootstrap/ui-bootstrap.js',
          'node_modules/angular-ui-form-validation/dist/angular-ui-form-validation.js',
          'node_modules/angular-animate/angular-animate.js',
    
          // client files
          'client/app/app.module.js',
          'client/app/app.controller.js',
          'client/app/**/*.service.js',
          'client/app/**/*.directive.js',
          'client/app/**/*.module.js',
          'client/app/**/*.state.js',
          'client/app/**/*.controller.js',
          'client/app/**/*.spec.js'
    
    Run Code Online (Sandbox Code Playgroud)

只有这样,测试才开始重新开始.