you can test whole directive with $compile - as John demonstrated.

directive controller can not directly access other controllers. you can 
workaround this, to pass them via scope.

On Thursday, March 27, 2014 7:34:10 PM UTC+1, Nikita Tovstoles wrote:
>
> I find it easier to unit-test controllers vs. link() functions since it's 
> easy to inject $scope into former in beforeTest() and thus subsequently 
> access $scope properties and methods for unit-testing. ie:
>
> var scope = {};
>
> beforeEach(function(){
> $controller(MyCtrl, {$scope:scope});
> })
>
> it('test scope.foo(), function(){
> expect(scope.foo()).toBe();///etc.
> });
>
> Seems like there is not a way to do the same for link() functions - 
> without modifying build process. Thus, no easy way to unit-test 
> scope.foo(), if declared inside a link() function *(right?)*
>
> ...which may be OK since I can just declare foo() inside controller. One 
> issue with keeping logic inside directive controller vs link() that I 
> encountered is dependency on injected ngModelCtrl (ie for directives which 
> require latter). *Is there a way to inject that ctrl instance into 
> directive controller (similar to $element)?* I only came up with:
>
> link: function(scope,element, attrs, ngModel){
> scope.$ngModel = ngModel; //for use in directive controller
> }
>

-- 
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