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?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to