title: How do you test observables in the ngOnInit lifecycle?
body: <p>I've seen tons of articles on testing observables, including <a href="https://medium.com/@bencabanes/marble-testing-observable-introduction-1f5ad39231c" rel="nofollow noreferrer">writing marble tests</a> and somehow I still can't find a straight answer on how to test a simple observable in my component in my ngOnInit cycle.</p>
  <pre><code>ngOnInit(): void {
      this.selectedMembers$.subscribe((members) =&gt; {
          if (!!members) {
              this.store.dispatch(actions.getPCPs());
          }
      });
  
      this.membersForm.valueChanges.subscribe((id) =&gt; {
          if (!!id.member_id) {
              if (id.member_id === 'null') {
                  this.store.dispatch(actions.getMembers());
  
                  return;
              }
              this.store.dispatch(
                  actions.getSelectedMember({ member_id: id.member_id }),
              );
          }
      });
  
      this.config$.subscribe((config) =&gt; {
          if (!!config) {
              config.mobile_filters.controls.forEach((control) =&gt; {
                  this.formControlService.addControlToFormGroup(
                      this.mobileFiltersForm,
                      control,
                  );
              });
          }
      });
  }
  </code></pre>
  <p>In there a straight forward way to spyOn this component and check that these observables are emitting something?</p>
  <pre><code> it('should test observables in ngOnInit', fakeAsync(() =&gt; {
      spyOn(component.selectedMembers$, 'subscribe')
      let myData;
      component.selectedMembers$.subscribe((data) =&gt; {
          myData = data;
          console.log('data',data);
          expect(myData).toEqual(data);
      })
  }));
  </code></pre>