title: Angular unit test if component method is called according to a data from a service
body: <p>I can't figure out how to test if a component method is fired or not on service data condition...</p>
  
  <p>service looks like:</p>
  
  <pre><code>@Injectable()
  export class SomeService {
  
      someData() {
          return true;
      }
  }
  </code></pre>
  
  <p>comp:</p>
  
  <pre><code>export class SomeComponent {
  
      constructor(private someService: SomeService) { 
  
          if (this.someService.someData()) {
              this.someMethod();
          } else {
              console.log('keep kalm!');
          }
      }
  
      someMethod() {
          console.log('some method is fired!')
      }
  }
  </code></pre>
  
  <p>test:</p>
  
  <pre><code>describe('SomeComponent', () =&gt; {
      let component: SomeComponent;
      let fixture: ComponentFixture&lt;SomeComponent&gt;; 
  
      let mockSomeService = {
          someData: () =&gt; true
      }
  
      beforeEach(async(() =&gt; {
          TestBed.configureTestingModule({
              declarations: [SomeComponent],
              providers: [
                  {
                      provide: SomeService, useValue: mockSomeService
                  }
              ]
          })
          .compileComponents();
      }));
  
      beforeEach(() =&gt; {
          fixture = TestBed.createComponent(SomeComponent);
          component = fixture.componentInstance;
          fixture.detectChanges();
      });
  
      it('method should be called', () =&gt; {
          spyOn(component, 'someMethod'); 
  
          expect(component.someMethod).toHaveBeenCalled(); 
      });
  });
  </code></pre>
  
  <p>The component someMethod fires but test fails with:</p>
  
  <blockquote>
    <p>Expected spy someMethod to have been called.</p>
  </blockquote>
  
  <p>How can I fix this?</p>
  
  <p>Thanks in advance!</p>