Javascript AngularJS单元测试模块冲突

Javascript AngularJS单元测试模块冲突,javascript,angularjs,unit-testing,mocha.js,karma-runner,Javascript,Angularjs,Unit Testing,Mocha.js,Karma Runner,我有几个模块,根据需要在不同的地方编写代码: angular.module('hthsLunch.landingPage', [ 'hthsLunch.core.authService', 'hthsLunch.core.messageService' ]); angular.module('hthsLunch.user', ['hthsLunch.core.authService']); angular.module('hthsLunch.order', [ 'hthsLunch.

我有几个模块,根据需要在不同的地方编写代码:

angular.module('hthsLunch.landingPage', [
  'hthsLunch.core.authService',
  'hthsLunch.core.messageService'
]);
angular.module('hthsLunch.user', ['hthsLunch.core.authService']);
angular.module('hthsLunch.order', [
  'hthsLunch.core.itemService',
  'hthsLunch.core.orderService',
  'hthsLunch.core.userService',
  'hthsLunch.core.authService',
  'hthsLunch.core.databaseService'
]);
angular.module('hthsLunch.panel', [
  'ngResource',
  'hthsLunch.core.messageService'
]);

angular.module('hthsLunch', [
  'ngMaterial',
  'ui.router',
  'hthsLunch.landingPage',
  'hthsLunch.user',
  'hthsLunch.order',
  'hthsLunch.panel'
]).config(['$locationProvider', '$mdThemingProvider',
  function($locationProvider, $mdThemingProvider) {
    $locationProvider
      .html5Mode(true)
      .hashPrefix('!');

    $mdThemingProvider
      .theme('default')
      .primaryColor('blue')
      .accentColor('green');
  }
]);

我正在尝试测试模块hthsflunch.panel中的过滤器,但无法在每个模块“hthsflunch.panel”之前进行测试;因为这会导致模块依赖性错误。由于某种原因,我无法在每个模块“hths午餐”之前执行此操作,因为此时筛选器似乎未定义。如何使用此模块结构正确编写单元测试?

测试过滤器的正确方法是您建议的第一种方法—只加载定义过滤器的hthsLunch.panel模块。如果执行此操作时出现模块依赖项错误,请确保已将那些缺少的依赖项与karma一起加载。但我认为加载ui路由器没有意义,因为我没有在.panel模块中使用它。有没有更好的方法来组织模块?ui路由器不是hthsLunch.panel的依赖项?如果它是通过HSLunun.C.MeasAgService间接的,那么你可以考虑重构该模块的依赖关系。“服务”模块可能不需要路由器作为依赖项。我在.panel模块中声明了一些路由,因此它取决于是否有权访问$stateProvider。