title: Angular testing mock subscribed property
body: <p>I have a service with 2 properties:</p>
  
  <h2>Service</h2>
  
  <pre><code>...
  public usernameAnnounced;
  private username: Subject&lt;string&gt; = new Subject&lt;string&gt;();
  
  constructor() {
      super();
      this.usernameAnnounced = this.username.asObservable();
  }
  </code></pre>
  
  <p>On my component I want to subscribe to the property:</p>
  
  <h2>Component</h2>
  
  <pre><code>    public ngOnInit(): void {
      this.service.usernameAnnounced.subscribe((username: string) =&gt; {
          this.username = NavbarComponent.capitalizeFirstLetter(username);
      });
  }
  </code></pre>
  
  <p>I emit to the username on another comp. but its irrelevant for this question.
  Now I want to mock usernameAnnounced but I have difficulties with it. I tried it with <code>spyOn</code> and it throws me a: 'usernameAnnounced is not a function.' 
  with <code>spyOnProperties</code> it throws me a : 'property is not a getter'.</p>
  
  <h2>Tested comp.</h2>
  
  <p>so far my approach looks as follows:</p>
  
  <pre><code>    beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
          ...
          declarations: [NavbarComponent],
          providers: [
              ...,
              {provide: service, useValue: authenticationMock}
              ]
          })
          .compileComponents();
  
      fixture = TestBed.createComponent(NavbarComponent);
  }));
  ...
      it('should render username',() =&gt; {
      const underTest = fixture.componentInstance;
  
      spyOnProperty(authenticationMock, 'usernameAnnounced').and.returnValue({
              subscribe: () =&gt; {'boboUser'}}); &lt;== important part here
  
      underTest.ngOnInit();
      fixture.detectChanges();
  
      const compiled: HTMLElement = fixture.debugElement.nativeElement.querySelector('#userName');
      const rendered: string = compiled.textContent;
  
      expect(rendered).toMatch(`Logged in as: ${underTest.username}`);
  });
  </code></pre>
  
  <p>Does someone has any hints?</p>