Testing functions are not in scope AND without the "this" keyword in the controller

This question is a piggy, if you want, from a previous SO question linked here: Testing off-scope functions in a controller

I have a similar problem that I am facing but cannot find the answer. I am also using Karma test runner and Jasmine. I also know how to test functions in scope and with the "this" keyword. However, I cannot find a way to unit test a function that is out of scope and unrelated to the "this" keyword.

The following function 'foo' is an example of a function that runs when the application loads. Inside this function, I have some logic that I would like to unit test.

controller('myController',function(){

    //calls function foo once the page loads
    foo();

    function foo(){
        //completes tasks on load
    };


});

      

Jasmine / Karma doesn't recognize my reference to 'foo', so I can't unit test any logic inside. I was told that these types of functions in AngularJS are NOT ani patterns. Any advice on how I could unit test them?

+3
javascript angularjs karma-jasmine


source to share


No one has answered this question yet

See similar questions:

0
Test functions are outside the scope of the controller

or similar:

6493
var functionName = function () {} vs function functionName () {}
2644
Is there a function "exists" for jQuery?
2633
How do I check for an empty JavaScript object?
2256
Set default parameter value for JavaScript function
1850
What is the scope of variables in JavaScript?
1647
What is a "new" keyword in JavaScript?
1201
How does the "this" keyword work?
1073
How to use $ scope. $ Watch and $ scope. $ Apply in AngularJS?
912
'this' vs $ scope in AngularJS controllers
806
Working with $ scope. $ Emit and $ scope. $ On



All Articles
Loading...
X
Show
Funny
Dev
Pics