title: How to test BehaviourSubject next function?
body: <p>I am trying to test a service that is using a <code>BehaviourSubject</code>, however I am not exactly sure how. Here is my service:</p>
  
  <pre><code>export class ProductService {
    private changes$: BehaviorSubject&lt;User[]&gt; = new BehaviorSubject([]);
  
    get products() { return this.changes$.asObservable() as Observable&lt;any&gt;; }
  
    getProducts() {
      this.http.get(...)
        .subscribe((products) =&gt; {
          this.changes$.next(products);
      }
    }
  
    filterById(id: number) {
      let products = this.products$.getValue().filter(...);
      // Maybe I will have some more filter logic here. 
      // I want to test that the filter logic is returning the correct product
      this.changes$.next(products);
    }
  ...
  }
  </code></pre>
  
  <p>Here is my test. I want to be able to test the filter logic of my service. But since I am mocking the data, <code>this.product$.getValue()</code> will be empty and the filter will not run. </p>
  
  <pre><code>it('should filter the products and return the correct product)',
      inject([ProductService], (service: ProductService) =&gt; {
        const usersSpy = spyOnProperty(service, 'products', 'get').and.returnValue(Observable.of(mockGetResponse));
        service.products.subscribe((res) =&gt; {
          // How do I continue here?  
          // the `this.products$.getValue()` 
          // will not contain any items, 
          // because I am mocking the data. 
          service.findByUserId(1); 
        });
      }));
  </code></pre>