Error Unit testing Angular 8 / Jasmine / Karma : RangeError: Maximum call stack size exceeded

Viewed 1693

I'm using Jasmine to unit test my angular app and sometimes this error below occurs in the Karma window. I can't find where it could come from since it happens about 1/5 times on reloading. It happens when in watch mode. Any clue?

zone.js:202 Uncaught RangeError: Maximum call stack size exceeded
      at RegExp.exec (<anonymous>)
      at Array.<anonymous> (VM2578 browser-source-map-support.js:110)
      at VM2578 browser-source-map-support.js:102
      at d (VM2578 browser-source-map-support.js:103)
      at q (VM2578 browser-source-map-support.js:106)
      at VM2578 browser-source-map-support.js:107
      at Array.map (<anonymous>)
      at Function.w [as prepareStackTrace] (VM2578 browser-source-map-support.js:107)
      at VM2580 jasmine.js:897
      at onerror (VM2580 jasmine.js:3199)

Most of the time, after reloading the karma window once, the test sets run again and it works.

2 Answers

Using the option ng test --source-map=false prevents the error from happening, but isnt a permanent solution since it obviously just disables source maps and makes stack traces useless.

Using this option in ci prevents the tests from failing though.

Ran into this issue myself, managed to resolve it by importing the routing module in the specific spec file that was throwing the error.

Related