简体   繁体   English

Angular JS错误:[$ injector:nomod]模块'portfolioMockupApp.services'不可用

[英]Angular JS Error: [$injector:nomod] Module 'portfolioMockupApp.services' is not available

I'm attempting to write some unit tests with Karma and am receiving the following error: 我正在尝试用Karma编写一些单元测试,并收到以下错误:

PhantomJS 1.9.8 (Mac OS X) ERROR Error: [$injector:nomod] Module 'portfolioMockupApp.services' is not available! PhantomJS 1.9.8(Mac OS X)错误错误:[$ injector:nomod]模块'portfolioMockupApp.services'不可用! 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. 如果注册模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.3.3/ $injector/nomod?p0=portfolioMockupApp.services at /Users/danielbogart/Documents/coding/work/portfolio-mockup/bower_components/angular/angular.js:1749 http://errors.angularjs.org/1.3.3/ $ injector / nomod?p0 = portfolioMockupApp.services atUsers/danielbogart/Documents/coding/work/portfolio-mockup/bower_components/angular/angular.js:1749

Also, I have two separate files within the portfolioMockupApp.services module, both saved in the scripts/services directory. 另外,我在portfolioMockupApp.services模块中有两个单独的文件,它们都保存在scripts / services目录中。

Karma.conf files section: Karma.conf文件部分:

  files: [

  'bower_components/angular/angular.js',
  'bower_components/angular-mocks/angular-mocks.js',
  'bower_components/angular-animate/angular-animate.js',
  'bower_components/angular-cookies/angular-cookies.js',
  'bower_components/angular-resource/angular-resource.js',
  'bower_components/angular-sanitize/angular-sanitize.js',
  'bower_components/angular-touch/angular-touch.js',

  'test/mock/**/*.js',
  'test/spec/**/*.js',
  'app/scripts/services/*.js',
  'app/scripts/directives/*.js',
  'app/scripts/controllers/*.js',
  'app/scripts/app.js',
  'node_modules/angular/angular.js',
  'node_modules/angular-mocks/angular-mocks.js',
  './src/**/*.js',
  './test/**/*.js'
],

Portfolio.js spec (first and only test currently): Portfolio.js规范(当前第一次也是唯一的测试):

'use strict';

describe('Controller: PortfolioCtrl', function () {

// load the controller's module
beforeEach(module('portfolioMockupApp', 'portfolioMockupApp.services'));

var PortfolioCtrl,
scope;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $scope, $log, $stateParams, $state, 

$rootScope,portService, portfolioCreateService) {
scope = $rootScope.$new();
PortfolioCtrl = $controller('PortfolioCtrl', {
  $scope: scope
  });
}));

it('should have a list of 5 tabs by default', function () {
  expect(scope.tabs.length).toBe(5);
  });
});

The problem stemmed from having two separate service files using the same service module. 问题源于使用相同服务模块的两个单独的服务文件。 In the Karma.conf file I had to explicitly load the service file that initialized the module, and then the other service file and rest of the app afterwards. 在Karma.conf文件中,我必须显式加载初始化模块的服务文件,然后加载其他服务文件和应用程序的其余部分。

  'app/scripts/services/port-service.js',
  'app/scripts/services/new-port-service.js',
  'app/scripts/app.js',
  'app/scripts/services/*.js',
  'app/scripts/directives/*.js',
  'app/scripts/controllers/*.js',

Thanks for checking back in with a solution. 感谢您使用解决方案重新检入。 I had this same issue when two modules relied on each other and existed in the same folder, lets call them app/scripts/parentModule.js and app/scripts/constants.js. 当两个模块相互依赖并存在于同一文件夹中时,我遇到了同样的问题,我们称之为app / scripts / parentModule.js和app / scripts / constants.js。 Both should be picked up by the wildcard entry in karma.config.js. 两者都应该被karma.config.js中的通配符条目选中。

'app/scripts/*.js'
'app/scripts/anotherFolder/*.js'

Since constants.js relies on parentModule.js, the later must be included first and my guess is the wildcard was including the files alphabetically but I've not confirmed this yet. 由于constants.js依赖于parentModule.js,因此必须首先包含后者,我的猜测是通配符按字母顺序包含文件,但我还没有确认。

'app/scripts/parentModule.js'
'app/scripts/*.js'
'app/scripts/anotherFolder/*.js'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:[$ injector:nomod]模块不可用 - Error: [$injector:nomod] Module is not available Angular / Karma:错误:[$ injector:nomod]模块'模块'不可用 - Angular/Karma: Error: [$injector:nomod] Module 'module' is not available Angular.JS:由于以下原因而无法实例化模块路由:错误:$ injector:nomod模块“路由”不可用 - Angular.JS: Failed to instantiate module routing due to: Error: $injector:nomod Module 'routing' is not available Angular JS,错误:[$ injector:nomod]模块'blogger.posts.controllers'不可用 - Angular JS, Error: [$injector:nomod] Module 'blogger.posts.controllers' is not available Angular js:Uncaught Error:[$ injector:nomod]模块不可用 - Angular js : Uncaught Error: [$injector:nomod] module unavailable 错误:[$ injector:nomod]模块“ nvd3”不可用 - Error: [$injector:nomod] Module 'nvd3' is not available 未捕获的错误:[$injector:modulerr] 错误:[$injector:nomod] 模块“chart.js”不可用 - Uncaught Error: [$injector:modulerr] Error: [$injector:nomod] Module 'chart.js' is not available Angular JS未捕获错误:[$ injector:nomod] - Angular JS Uncaught Error: [$injector:nomod] AngularJS:未捕获的错误:[$injector:nomod] 模块 _ 不可用! | 对模块的多次引用 - AngularJS: Uncaught Error: [$injector:nomod] Module _ is not available! | Multiple References to Module “错误:$ injector:nomod模块不可用” - “Error: $injector:nomod Module Unavailable”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM