title: Jasmine Test Subject.subscribe
body: <p>I have below line of code </p>
  
  <pre><code>@Input() saveData: Subject&lt;{ activeTab: string, callOnInit: boolean, Code: number, evnt: any }&gt;;
  ngOnInit() {
  
      // perform component logging
      this.performLogging();
  
      this.isAttachment = this.parentData.isAttachment;
      this.getOnloadData();
      if (this.saveData) {
          this.saveData.subscribe(v =&gt; {
              if (v &amp;&amp; v.activeTab === 'attachment' &amp;&amp; !v.callOnInit) {
                  this.saveAttachment('parent', v.Code, v.evnt);
              } else if (v &amp;&amp; v.activeTab === 'attachment' &amp;&amp; v.callOnInit) {
                  this.ngOnInit();
              }
         });
       }
  }
  </code></pre>
  
  <p>How to write test cases to cover the code inside this.saveData.subscribe(v => {});</p>
  
  <pre><code>if (v &amp;&amp; v.activeTab === 'attachment' &amp;&amp; !v.callOnInit) {
              this.saveAttachment('parent', v.Code, v.evnt);
          } else if (v &amp;&amp; v.activeTab === 'attachment' &amp;&amp; v.callOnInit) {
              this.ngOnInit();
          }
  </code></pre>
  
  <p>Below is my test Case written using Jasmine &amp; Karm.</p>
  
  <pre><code>it('should create', () =&gt; {
  spyOn(component.saveData,'subscribe').and.callThrough();
  component.saveData = new Subject();
  component.saveData.next({
    activeTab: "",
    callOnInit: true,
    Code: 41,
    evnt: {}  
  });    
  fixture.detectChanges();
  component.ngOnInit();    
  expect(component.saveData.subscribe).toHaveBeenCalled();});
  </code></pre>