title: Writing unit test for subscription inside onInit() in Angular
body: <p>I have a Spinner Component class as below which would show/hide Progress Spinner using Angular material.  </p>
  
  <pre><code>export class SpinnerComponent implements OnInit, OnDestroy {
      visible = true;
      private subscription: Subscription;
  
      constructor(private spinnerService: SpinnerService) {}
  
      ngOnInit() {
           this.subscription = this.spinnerService.spinnerState.subscribe((state: SpinnerState) =&gt; {
                  this.visible = state.show;
             });
       }
      ngOnDestroy() {
           if (this.subscription) {
              this.subscription.unsubscribe();
           }
      }
  }
  </code></pre>
  
  <p>How can I write a spec which could test for the specific line shown below which is inside the ngOnInit() method ? </p>
  
  <pre><code>this.visible = state.show;
  </code></pre>