I am new in unit testing with Jasmine in Angular.
I am currently testing a service that has a function called loadSomething(id) and I have added a console.info in it.
MY SERVICE:
function loadSomething(id)
{
console.info('this is a test message');
return (a promise from a POST request)
}
And this is my test (spec) file:
//verify that the load function exists
it('load snapshot',function(){
expect(MyService.loadSomething(108)); //statement 1
spyOn(MyService, 'loadSomething').and.callThrough(); //statement 2
});
So, I read online that the callthrough method of SpyOn calls the ACTUAL function. However, when i run my test with the expect statement (statement 1) the console.info message is invoked (that works fine). On the other hand, when I comment out statement 1 and uncomment the SpyOn(statement 2) I do not get the console.info message anymore.
I would expect the exact opposite to happen. Have I understood something wrong here?
(the rest of the code works fine, both the spec file and the actual service, I just don't really get this specific thing)