angularjs - Angular Unit Testing: How do i call a named function -


i have controller, contains named function.

function controller($scope, ...){    function foo(data){       //logic other stuff      $log(data);  }   //some promise stuff waiting.then(function(data){   foo(data); }); 

for way functions available, didnt want assign foo scope variable, since doing this:

$scope.foo = function(data) {} 

was frowned upon? (not sure...but since not calling foo view, dont see why would)

my issue is, how call foo function unit test "it" block?

i.e

  it('expect calling function', function(){     foo(data); }); 

this gives me error

call foo function outside controller impossible, because foo closure - inner function defined , available within controller function body. see https://developer.mozilla.org/cs/docs/web/javascript/closures#lexical_scoping

i prefer controlleras syntax angular controller. controller ordinary object constructor properties , method defined on this. binding scope arises during evaluation ng-controller directive (or route display).

generally can create controller instance in test, mock dependencies (waiting) , use spies assert function call more easily.

http://toddmotto.com/digging-into-angulars-controller-as-syntax/


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -