Karma / Jasmine超出最大调用堆栈大小

时间:2017-08-23 18:25:39

标签: angularjs jasmine karma-runner karma-jasmine

修改:其他人看起来有类似的错误here 编辑2 :这似乎是针对Chrome的,因为Firefox可以运行。

我的测试正在运行,现在出现错误:

RangeError: Maximum call stack size exceeded
            at Object.invoke (lib/angular/angular.js:4771:19)
            at lib/angular/angular.js:4578:62
            at forEach (lib/angular/angular.js:325:20)
            at Object.createInjector [as injector] (lib/angular/angular.js:4578:3)

我尝试创建一个简单的测试,我相信问题是当我尝试注入模板时。我正在使用 karma-ng-html2js-preprocessor 来编译我的模板,我认为可能因为依赖项的更改而导致库被破坏。验证这实际上是问题的最佳方法是什么?我查看了Git仓库,并确认它有十几个过时的依赖关系,但这并不一定意味着它被打破了。

Karma.conf

module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine'],

    files: [
        'spec/testData/**/*.js',
        'spec/helpers/bundle/tisfBundle.js',
        'lib/jquery/dist/jquery.js',
        'lib/angular/angular.js',
        'lib/angular-resource/angular-resource.js',
        'lib/angular-sanitize/angular-sanitize.js',
        'lib/angular-ui-router/release/angular-ui-router.js',
        'lib/angular-bootstrap/ui-bootstrap.js',
        'lib/angular-mocks/angular-mocks.js',
        'lib/tisf-angular/build/js/tisf-angular.js',
        'lib/twix/dist/js/twix.js',
        'lib/spin.js/spin.js',
        'lib/angular-ui-router/release/angular-ui-router.js',
        'spec/app/*Spec.js',
        'spec/app/**/*Spec.js',

        'app/modules/directives/*.js',
        'app/modules/tcm-help-app.js',

        'app/modules/views/home/*.js',
        'app/modules/views/home/**/*.js',
        'app/modules/services/**/*.js',
        'app/modules/directives/**/*.js',

        'app/modules/views/home/*.html',
        'app/modules/directives/**/*.html',

        '**/*.html'
    ],

    exclude: [
    ],

    preprocessors: {
        '**/*.html': ['ng-html2js'],
        'app/modules/views/home/**/*.html': ['ng-html2js'],
        'app/modules/views/home/*.html': ['ng-html2js'],
        'app/modules/directives/**/*.html': ['ng-html2js']
    },

    ngHtml2JsPreprocessor: {
        prependPrefix: '/',
        moduleName: 'tcmTemplates'
    },

    reporters: ['spec'],
    specReporter: {
    maxLogLines: 5,
    suppressErrorSummary: true,
    failFast: true
    },

    port: 9876,    

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: ['Chrome'],

    singleRun: false, 

    concurrency: Infinity
  })
};

样本测试

describe('Home', function () {
    beforeEach(angular.mock.module('tcm-help-ui'));
    beforeEach(module('tcmTemplates')); //test works without this line

    var $homeController, scope;

    beforeEach(inject(function ($rootScope, _$controller_) {
        scope = $rootScope.$new();
        $homeController = _$controller_;
    }));

    describe('HomeController', function () {
        var $ctrl;
        beforeEach(function () {
            $ctrl = $homeController('tcmHomeController', {$scope: scope});
        });

        it('should be defined', function() {
            expect($ctrl).toBeDefined();
        });

    });
});

0 个答案:

没有答案