PS. I suppose I should have titled the below as 'how do I unit-test scope
methods declared inside link()?'


On Thu, Mar 27, 2014 at 11:34 AM, Nikita Tovstoles <
[email protected]> 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 a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/1yiCh41gb28/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>

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