Given this simple component :
import { Component} from '@angular/core';
@Component({
selector: 'app-component'
})
export class AppComponent {
foo() {
this.bar();
}
bar() {
console.log('hello');
}
}
How come the following test won't validate that bar
is called when I call foo
describe('AppComponent', () => {
let component: AppComponent;
beforeEach(() => {
component = new AppComponent();
}
it('should foobar', () => {
component.foo();
spyOn(component, 'bar');
expect(component.bar).toHaveBeenCalled();
})
}
I get the failed test :
Expected spy bar to have been called.