Wie zu injizieren controller Abhängigkeiten in Jasmin-tests?

Gibt es die folgenden controller-definition:

angular.module('app.controllers', []).controller('HomeController', [
  '$scope', '$modal', 'Point', function($scope, $modal, Point) { //some action }

Möchte ich dies testen-controller:

describe('HomeController', function() {
  beforeEach(module('app.controllers'));

  var $controller;

  beforeEach(inject(function(_$controller_){
    //The injector unwraps the underscores (_) from around the parameter names when matching
    $controller = _$controller_;
  }));

  describe('$scope.grade', function() {
    it('sets the strength to "strong" if the password length is >8 chars', function() {
      var $scope = {};
      var controller = $controller('HomeController', { $scope: $scope });
      $scope.label = '12345';
      $scope.addNewPoint();
      expect($scope.label).toEqual(null);
    });
  });
});

"Punkt" ist mein individueller service, "$modal" ist Kantig Bootstrap-Modul. Wie kann ich Spritzen in meinen tests? Vielen Dank im Voraus!

InformationsquelleAutor malcoauri | 2015-09-16
Schreibe einen Kommentar