James Kingsbery
James Kingsbery

Reputation: 7496

How to reproduce the "10 $digest() iterations reached. Aborting" error in Jasmine

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.

Upvotes: 3

Views: 524

Answers (1)

Anirudh
Anirudh

Reputation: 125

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

Upvotes: 1

Related Questions