title: Angular Unit Test Mock Replay Subject
body: <p>I have a service with a replay subject.</p>
  
  <pre><code>export class UserService {
    public userChanged: ReplaySubject&lt;User&gt; = new ReplaySubject&lt;User&gt;();
  
  ...
  public getUser(userId?): void {
      ...
      this.http.get(url, httpOptions).pipe(
        catchError(this.handleError('getUser', null, 'Couldn\'t get user', options))
      ).subscribe( (user: User) =&gt; {
  
         this.userChanged.next(user);
  
      });
    }
  </code></pre>
  
  <p>My component subscribes to <code>userChanged</code>.</p>
  
  <pre><code>this.userService.userChanged.subscribe((user) =&gt; {
    this.user = user;
  });
  </code></pre>
  
  <p>Now, I want to mock my <code>UserService</code> in the component test:</p>
  
  <p>1 option <a href="https://netbasal.com/testing-observables-in-angular-a2dbbfaf5329" rel="nofollow noreferrer">Testing Observables in Angular</a>)</p>
  
  <pre><code>import { of } from 'rxjs';
  ...
      const userServiceSpy = jasmine.createSpyObj('UserService', {'userChanged': of({_id: '1'}) });
  </code></pre>
  
  <p>or 2 option)</p>
  
  <pre><code>    const userServiceSpy = jasmine.createSpyObj('UserService', {'userChanged': () =&gt; of({_id: '1'}) });
  </code></pre>
  
  <p>or 3 option <a href="https://angular.io/guide/testing#testing-with-a-spy" rel="nofollow noreferrer">angular test tutorial</a>)</p>
  
  <pre><code>const userServiceSpy = jasmine.createSpyObj('UserService', ['userChanged']});
  const userChangedSpy = userServiceSpy.userChanged.and.returnValue( of({_id: '1'})  );
  </code></pre>
  
  <p>+</p>
  
  <pre><code>TestBed.configureTestingModule({
    ...
    providers: [
      ...
      {provide: UserService, useValue: userServiceSpy}
    ],
    schemas: [NO_ERRORS_SCHEMA]
  })
  </code></pre>
  
  <p>give me this err:</p>
  
  <pre><code>this.userService.userChanged.subscribe is not a function
  </code></pre>
  
  <p>Shouldn't <code>of</code> return an Observable to subscribe to?</p>
  
  <p>Question: How to mock this?</p>