I have a directive that uses a controller by listing it using the required
property, not the controller
property like this:
module('some-module').directive('someDirective', function() {
return {
require: 'someCtrl',
restrict: 'A',
transclude: false,
link: function(scope, element, attr, controller) {
//do something
}
};
});
I want to unit test this, but my tests complain that it can't find the required controller someCtrl
, possibly because I'm using angularMocks.module
to declare all my modules in my tests, rather than angular.module
. However, when I change the directive to specify the controller with controller
it works:
`controller: 'someCtrl`
I'm trying to inject a mock controller using $controllerProvider.register
in my tests:
var scope;
beforeEach(function() {
angularMocks.module(function($controllerProvider) {
$controllerProvider.register('someCtrl', function() {
//mock controller behavior
});
inject([
'$rootScope',
function($rootScope) {
$scope = $rootScope.$new();
}
]);
});
});
it('should do something', function() {
$compile('<div some-directive></div>')($scope); //It breaks on this line
});
What's the reason it can't find the controller when specified with require
but it works fine when specified with controller
?