title: How to test a component with @Input and type Observable
body: <p>I am little new to writing unit tests for Angular and not able to figure out how I can write unit tests for a component with a @Input directive.</p>
  
  <p>Here is my </p>
  
  <p>== file.component.ts</p>
  
  <pre><code>import { Component, OnInit, Input } from '@angular/core';
  
  @Component({
    selector: 'app-bugs-table',
    templateUrl: './bugs-table.component.html',
    styleUrls: ['./bugs-table.component.scss']
  })
  export class BugsTableComponent implements OnInit {
  //   priorityData: any = [];
    @Input() bugsDataService;
    @Input() gridItemComponent;
    constructor(
    ) {  }
  
    ngOnInit() {
  
    }
      ngAfterViewInit() {
  this.bugsDataService.subscribe(response =&gt; {
    this.bugsData = response;
  })
  </code></pre>
  
  <p>}
      }</p>
  
  <h1>Here is my file.component.spec.ts</h1>
  
  <pre><code>import { async, ComponentFixture, TestBed } from '@angular/core/testing';
  import { FormsModule, ReactiveFormsModule, } from '@angular/forms';
  import { HttpModule, BrowserXhr } from "@angular/http";
  
  fdescribe('BugsTableComponent', () =&gt; {
    let component: BugsTableComponent;
    let fixture: ComponentFixture&lt;BugsTableComponent&gt;;
    beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
        declarations: [ BugsTableComponent ],
        imports: []
      })
      .compileComponents();
    }));
  
    beforeEach(() =&gt; {
      fixture = TestBed.createComponent(BugsTableComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
  
    fit('should create', () =&gt; {
      expect(component).toBeTruthy();
    });
  });
  </code></pre>
  
  <p>But it fails with error:</p>
  
  <blockquote>
    <p>× should create
          HeadlessChrome 69.0.3497 (Windows 10.0.0)
        TypeError: Cannot read property 'subscribe' of undefined</p>
  </blockquote>
  
  <p>I know this is because bugsDataService (which is a observable) is undefined.
  Can any please help fixing this. 
  Please let me know if you need more info.</p>