lundi 4 avril 2016

Testing angular controllers that have many dependencies

I am trying to test a controller.

someModule.controller('MyController', function($rootScope, $scope, dep1, dep2) {
  ...
  $scope.aMethod = function() {
    ...
  }
  ...
}]);

And I define my test this way:

beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
console.log($controller);
    MyController = $controller('MyController', {
$rootScope : $rootScope,
$scope: scope
    });
 console.log('Some debug message');
  console.log(MyController);
  }));

And I get this output:

LOG: function (expression, locals, later, ident) { ... }
LOG: 'Some debug message'
LOG: {}

Even if I put in dep1 and dep2 I get the same results. I have to have the two I added, which is why they are there, otherwise it throws an exception.

I am not certain why this isn't working.

Aucun commentaire:

Enregistrer un commentaire