3

There have been a few questions asked about how to address the error message:

10 $digest() iterations reached. Aborting,

for example this one. I get how to fix that - you change your code so it doesn't change the $scope during a digest.

What I'd like to do, and don't understand how to do, is reproduce this error as part of a Karma/Jasmine test. From what I've gathered, you need to manually force a digest to generally get digest updates, and that works for me in terms of forcing the initial digest (to resolve promises), but I don't see it force the $digest loop that eventually errors out.

Community
  • 1
  • 1
James Kingsbery
  • 7,298
  • 2
  • 38
  • 67
  • 2
    There aren't enough questions about how to cause an error, far too many about how to make it go away without understanding it. _To reach enlightenment, you must first understand how to fail._ – BanksySan May 05 '15 at 18:22

1 Answers1

1

This error occurs when a function returns different value each time it is called.

Example

$scope.getValue = function() {
  return Math.Random()
}
<div>{{ getValue() }}</div>

Running the above code will generate the error as it returns a different value each time.

Another example

$scope.getObjects = function() {
  return [object1, object2];
}
<div ng-repeat="object in getObjects"></div>

In the second example, we generate a new array every time which causes the error.

Reference : https://docs.angularjs.org/error/$rootScope/infdig

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
Anirudh
  • 125
  • 9
  • I appreciate you taking the time, but this doesn't answer the question. As I said, I know how to fix it, the question is how to reproduce in karma/jasmine. – James Kingsbery May 27 '15 at 12:17