因果报应;模块不可用'

Karma complains 'Module is not available'

本文关键字:模块 因果报应      更新时间:2023-09-26

直到几天前,我的单元测试运行得很好,我的代码在浏览器中运行得很完美。然后我在添加了一个名为"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.

现在,我意识到这是地球上最常见的AngularJS错误,我已经非常擅长调试它,但就我而言,我无法让它消失。详细信息:

  • 代码在浏览器中正常工作,没有任何错误
  • 因果报应以这种方式获取我的文件:

        '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'
    
  • 主模块已声明对"profile"的依赖项。

  • profile.js、profile.controller.js和profile.coontroller.spec.js是由cg-angular fullstack生成的存根,没有特殊代码。生成器默认情况下会将所有这些模块都粘贴在主模块中,因此我将每个模块的模块更改为"profile"

我完全没有主意了。如果我不能调试它,我将不得不假设我的整个应用程序设计有缺陷,然后重新启动。:(

不知何故,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'
    

直到那时,测试才重新开始工作。