Beim Testen von Winkeldirektiven: Wie kann ich eine Instanz des Directive Controllers greifen und bestimmte Datenbindungen auf dem Controller bestätigen?Instanz des Direktiven-Controllers mit Angular/Jasmine
function myDirective() {
return {
restrict: 'E',
replace: true,
templateUrl: 'tpl.html',
scope: { },
controller: function($scope) {
$scope.text = 'Some text';
}
};
}
angular
.module('example')
.directive('myDirective', [
myDirective
]);
Unit-Test
describe('<my-directive>', function() {
var element;
var $compile;
var $scope;
beforeEach(module('example'));
beforeEach(function() {
inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$scope = _$rootScope_.$new();
});
});
describe('basic functionality', function() {
beforeEach(function() {
element = $compile('<my-directive></my-directive')($scope);
$scope.$digest();
});
it('should bind the correct text', function() {
//?
});
});
});
Ist dies nicht für Sie arbeiten? https://docs.angularjs.org/guide/unit-testing#testing-a-controller –