title: Angular Unit Test: how to use marble testing (rxjs/testing) to test this state management service
body: <p>In my angular project, I have a service, which is used for state management to share some data between components as following:</p>
  
  <pre><code>@Injectable({ providedIn: "root"})
  export class NameStateService {
  
      private _filteredNames$: Subject&lt;Name[]&gt; = new Subject();
      private _filteredNamesObs$: Observable&lt;Name[]&gt;;
  
      constructor() {
          this._filteredNamesObs$ = this._filteredNames$.asObservable();
      }
  
      public updateFilteredNames(val: Name[]): void {
          this._filteredNames$.next(val);
      }
  
      public get filteredNames$(): Observable&lt;BillingAccount[]&gt; {
          return this._filteredNamesObs$;
      }
  }
  </code></pre>
  
  <p>the state management is based on subject and observable, which is typical usage in rxjs world. </p>
  
  <p>And For the unit test for this service, I want to use the marble testing features suppored by <code>rxjs/testing</code> module. The solution goes as following:</p>
  
  <pre><code>describe("Name state service ", () =&gt; {
      let nameStateService: NameStateService;
      let scheduler: TestScheduler;
  
      beforeEach(() =&gt; {
          TestBed.configureTestingModule({
              providers: [
                  NameStateService
              ]
          });
          nameStateService = TestBed.get(NameStateService);
          scheduler = new TestScheduler((actual, expected) =&gt; expect(actual).toEqual(expected));
      });
  
      it("should be created", () =&gt; {
          expect(nameStateService).toBeTruthy();
      });
  
      it("should return a valid names observables", () =&gt; {
          scheduler.run(({ cold, hot, expectObservable }) =&gt; {
              const mockNames: Name[] = [{
                  title: "title1",
                  group: "group1"
              }]; 
              nameStateService.updateFilteredNames(mockNames);
              expectObservable(nameStateService.filteredNames$).toBe("-b", {b: mockNames});
          });
      });
  })
  </code></pre>
  
  <p>But the second unit test failed with the error: <code>Error: Expected $.length = 0 to equal 1.</code> So it means that <code>nameStateService.filteredNames$</code>, this observable has no values in its stream. <br></p>
  
  <p>What is the issue here? </p>