I am trying to test whether or not a particular function was called in my Angular controller.
.controller('demo',function(){
function init(){
//some code..
}
init();
}
My test code looks something like below:
describe(..
beforeEach(...
function createController() { /*call this fn to create controller */
)
describe('controller initilization'.function(){
var spy = spyOn(this,init)
createController();
expect(spy).toHaveBeenCalled();
}
)
ofcourse the above unit test fails. So how would i check if the function init() was called ?
$scopewhen testing, unless you are writing E2E tests...