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


source to share





All Articles