参数IndexController不是函数,未定义:运行karma测试时

时间:2014-09-27 07:11:41

标签: angularjs testing jasmine karma-runner

这是我测试IndexController的测试文件

//modules/application/tests/spec/controllers/IndexController.js

'use strict';    
(function() {
    describe('Application IndexController', function() {
        beforeEach(function() {
            module('HtEwa');
            module('HtEwa.Application');
        });

        var scope, IndexController;

        beforeEach(inject(function($controller, $rootScope) {
            scope = $rootScope.$new();
            IndexController = $controller('IndexController', {
                $scope: scope
            });
        }));

        it('should expose global scope', function() {
            expect(scope.global).toBeTruthy();
        });
    });
})();

我已经看到了其他答案,但它对我不起作用。我的karma.conf.js中包含的文件是:

files:_.flatten(_.values(assets.core.js)).concat([
        'modules/*/*.js',
        'modules/*/*/*.js',
        'modules/*/tests/spec/*/*.js'
    ]);

我有HtEwaHtEwa.Application模块。在HtEwa.Application下有IndexController。

//modules/application/controllers/IndexController.js
    'use strict';
angular.module('HtEwa.Application').controller('IndexController', ['$scope', 'Global',
    function($scope, Global) {
        $scope.global = Global;    
    }
]);

我想我的IndexController文件没有包含在内,但我在modules/*/*/*.js中包含了karma.conf.js以及IndexController所在的那个。或者我错过了什么?

编辑: 业力--log-level debug表明所有需要的文件都已提供。 这是我从chrome看到的包含文件

 <!-- Dynamically replaced with <script> tags -->
  <script type="text/javascript" src="/base/node_modules/karma-jasmine/lib/jasmine.js"></script>
<script type="text/javascript" src="/base/node_modules/karma-jasmine/lib/adapter.js"></script>
<script type="text/javascript" src="/base/bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="/base/bower_components/angular/angular.js"></script>
<script type="text/javascript" src="/base/bower_components/angular-mocks/angular-mocks.js"></script>
<script type="text/javascript" src="/base/bower_components/angular-cookies/angular-cookies.js"></script>
<script type="text/javascript" src="/base/bower_components/angular-resource/angular-resource.js"></script>
<script type="text/javascript" src="/base/bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script type="text/javascript" src="/base/bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>
<script type="text/javascript" src="/base/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script type="text/javascript" src="/base/modules/application/application.js"></script>
<script type="text/javascript" src="/base/modules/application/controllers/FooterController.js"></script>
<script type="text/javascript" src="/base/modules/application/controllers/HeaderController.js"></script>
<script type="text/javascript" src="/base/modules/application/controllers/IndexController.js"></script>
<script type="text/javascript" src="/base/modules/application/init.js"></script>
<script type="text/javascript" src="/base/modules/application/routes/ApplicationRoutes.js"></script>
<script type="text/javascript" src="/base/modules/application/services/Global.js"></script>
<script type="text/javascript" src="/base/modules/application/services/HTTPInterceptor.js"></script>
<script type="text/javascript" src="/base/modules/application/tests/spec/controllers/IndexController.js"></script>
<script type="text/javascript" src="/base/modules/users/controllers/UserController.js"></script>
<script type="text/javascript" src="/base/modules/users/routes/Auth.js"></script>
<script type="text/javascript" src="/base/modules/users/services/UserService.js"></script>
<script type="text/javascript" src="/base/modules/users/tests/spec/controllers/UserController.js"></script>
<script type="text/javascript" src="/base/modules/users/users.js"></script>
  <script type="text/javascript">
    window.__karma__.loaded();
  </script>

1 个答案:

答案 0 :(得分:0)

尝试这样做:

files:_.flatten(_.values(assets.core.js)).concat([
    'modules/**/*.js'
]);

注意使用两个*。阅读 karma configuration documentation

中的文件模式示例

其中的例子是:

  • **/*.js:所有带有&#34; js&#34;的文件所有子目录中的扩展
  • **/!(jquery).js:与之前相同,但不包括&#34; jquery.js&#34;
  • **/(foo|bar).js:在所有子目录中,所有&#34; foo.js&#34;或&#34; bar.js&#34;文件