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

Several questions have been asked about how to address the error message:

10 $ digest () iterations. Cancel,

like this one . I understand how to fix this - you change your code so that it doesn't change $scope

in time digest

.

What I would like to do and do not understand how to do it reproduces this error as part of the Karma / Jasmine test. From what I've put together, you need to manually force the digest to get the digest updates normally, and that works for me in terms of forcing the initial digest (for the promises solution), but I don't see it forcing a loop $digest

that ends up was out of order.

+3


source to share


1 answer


This error occurs when the function returns a different value on each call.

Example

$scope.getValue = function() {
  return Math.Random()
}

      

<div>{{ getValue() }}</div>

      

Running the above code will throw an error because 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 each time that throws an error.

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

+1


source







All Articles