I'm trying to test a component, which has a constructor with multiple parameters. In the testing file (spec file), I've created a componentInstance using:
componentObject: fixture.componentInstance;
Also, I'm using this object to call a function that is defined in the component that prints a console like 'this function has been called'. But, when I do something like this:
it('checking console', async(() => {
spyOn(console, 'log');
componentObject.onClickFunction();
expect(console.log).toHaveBeenCalledWith('this function has been called');
}));
but it gives me an error saying:
Uncaught Expected spy log to have been called with [ 'this function has been called' ] but it was never called
so I'm guessing the function is not getting executed, though I have called it using 'componentObject.onClickFunction()'.
UPDATE: the onClickFunction() literally does nothing except printing logs,
onClickFunction() {
console.log('this function has been called');
}
Any suggestions?