testing that a component method calls another method : <p>Given this simple component :</p>

<pre><code>import { Component} from '@angular/core';

@Component({
  selector: 'app-component'
})
export class AppComponent {
  foo() {
    this.bar();
  }

  bar() {
    console.log('hello');
  }
}
</code></pre>

<p>How come the following test won't validate that <code>bar</code> is called when I call <code>foo</code></p>

<pre><code>describe('AppComponent', () =&gt; {
  let component: AppComponent;

    beforeEach(() =&gt; {
    component = new AppComponent();
  }

  it('should foobar', () =&gt; {
    component.foo();
    spyOn(component, 'bar');
    expect(component.bar).toHaveBeenCalled();
  })

}
</code></pre>

<p>I get the failed test :</p>

<pre><code>Expected spy bar to have been called.
</code></pre>
