Unit tests fail with $digest iterations loop after update to 1.3.4

70 views
Skip to first unread message

Kostas Subdee

unread,
Dec 10, 2014, 12:12:48 PM12/10/14
to ang...@googlegroups.com
I have the following in a controller that I am testing
   
angular.module('dashboard')
     
.controller('LoginCtrl', ['$scope', 'UserService', '$rootScope', '$state', 'PageTitle', '$translate',
       
function ($scope, UserService, $rootScope, $state, PageTitle, $translate) {
          $translate
('TITLE_LOGIN').then(function (text) {
           
PageTitle.setTitle(text);
         
});
          $scope
.credentials = {};
          $scope
.error = false;
          $scope
.loggingIn = false;
          $scope
.login = function () {
            $scope
.loggingIn = true;
           
UserService.login($scope.credentials)
             
.then(function (result) {
               
if (result) {
                  $scope
.error = false;
                  $state
.go('main.start');
               
} else {
                  $scope
.loggingIn = false;
                  $scope
.error = true;
               
}
             
}, function () {
                $scope
.loggingIn = false;
                $scope
.error = true;
             
});
         
};
       
}]);


where the service is calling some backend with $http.

The following is my test for the login function

   
describe('Controller: LoginCtrl', function () {
   
     
// load the controller's module
      beforeEach
(module('dashboard'));
   
     
var LoginCtrl,
        scope
,
        userSvc
,
        conf
,
        base64
,
        localStorage
,
        httpBackend
;
   
     
// Initialize the controller and a mock scope
      beforeEach
(inject(function ($controller, $rootScope, $httpBackend, UserService, configuration, Base64, localStorageService) {
        scope
= $rootScope.$new();
       
LoginCtrl = $controller('LoginCtrl', {
          $scope
: scope
       
});
        httpBackend
= $httpBackend;
        userSvc
= UserService;
        conf
= configuration;
        base64
= Base64;
        localStorage
= localStorageService;
        sessionStorage
.clear();
     
}));
   
      it
('should login', function () {
       
var token = base64.encode('1:1');
        httpBackend
.expectGET('scripts/i18n/nl.json').respond(200);
        httpBackend
.expectGET('views/login.html').respond(200);
        httpBackend
.whenPOST(conf.backend + 'users/login').respond({'access_token': 1});
        httpBackend
.expectGET('views/main.html').respond(200);
        httpBackend
.expectGET('views/start.html').respond(200);
        scope
.login({'email': 'tester'});
        httpBackend
.flush();
        expect
(sessionStorage.accessToken).toEqual(token);
        expect
(userSvc.profile()).toBeObject();
     
});
   
});

This test passes up to and including version 1.3.3, but at 1.3.4 I get the following error at httpBackend.flush()


    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
       
Watchers fired in the last 5 iterations: []
        http
://errors.angularjs.org/1.3.4/$rootScope/infdig?p0=10&p1=%5B%5D
            at
/srv/http/bower_components/angular/angular.js:14170
            at
/srv/http/bower_components/angular-mocks/angular-mocks.js:1523
            at
/srv/http/test/unit/controllers/login.js:38


From the changelog I couldn't figure out which of the changes would affect it. Any ideas?
Reply all
Reply to author
Forward
0 new messages