Karma Uncaught RangeError: Maximum call stack size exceeded

Karma Uncaught RangeError: Maximum call stack size exceeded

我在尝试 运行 grunt karma:debug:

时从 Karma 收到此错误
11 11 2017 00:00:00.000:INFO [Chrome 62.0.3202 (Linux 0.0.0)]: Connected on socket /#AAAA-AAAAAAAAAAAAAAA with id 99999999
Chrome 61.0.0000 (Linux 0.0.0) ERROR
  Uncaught RangeError: Maximum call stack size exceeded
  at http://localhost:9876/context.html
Chrome 61.0.0000 (Linux 0.0.0) ERROR
  Uncaught RangeError: Maximum call stack size exceeded
  at http://localhost:9876/context.html
Chrome 61.0.0000 (Linux 0.0.0): Executed 0 of 0 ERROR (1.035 secs / 0 secs)

可能是什么原因?在提交一些大 JSON 文件后,它开始在一夜之间发生。如果我在没有 JSON 文件的情况下返回提交,该命令将再次开始工作。

我在我的 karma.conf.js 文件中发现了问题:

config.set({
    ...
    files: [
        ...
        { pattern: "path/to/fixtures/**/*.json" },
        ...
    ]

该行使 Karma 将 JSON 文件包含在 HTML 页面中,并且它似乎无法处理我添加的 JSON 文件的数量。解决方案是告诉 Karma 不要将这些文件包含在 HTML 中,而是将它们作为 WebServer 提供:

config.set({
    ...
    files: [
        ...
        { pattern: "path/to/fixtures/**/*.json", included: false },
        ...
    ]

相关文档为here:

included
Type. Boolean
Default. true
Description. Should the files be included in the browser using
             <script> tag? Use false if you want to load them manually,
             eg. using Require.js.

确保您只分配了一次组件变量,最好只在顶部beforeEach

component = fixture.componentInstance - 这不应该在每个描述中给出。