Reputation: 3798
I have created a simple JS function which i want to test but when i run it is showing error Expected spy log to have been called what am i doing wrong ?
Function
function helloWorld() {
console.log('hey');
}
Test spec
describe('Hello world', function () {
it('says hello', function () {
spyOn(console,'log').and.callThrough();
expect(console.log).toHaveBeenCalled();
});
});
Upvotes: 2
Views: 7959
Reputation: 71
It's not an error, it's a failed test. That's because you don't call the log function in your example, so the test "correctly" fails.
describe('Hello world', function () {
it('says hello', function () {
spyOn(console,'log').and.callThrough();
comp.helloWorld();
expect(console.log).toHaveBeenCalled();
});
});
Upvotes: 7