title: Mock ngrx store selectors with parameters in unit tests (Angular)
body: <p>I am trying to write unit tests for a service in Angular.
  I want to mock the store.select function of ngrx, so I can test how let's say, a service, reacts to different values returned by the store selectors. I want to be able to mock each selector individually.</p>
  
  <p>My main problem is how to mock parametrised selectors.</p>
  
  <p>I have previously used a BehaviourSubject that I map to the select function, but this doesn't allow you to return different values for different selectors. It is not readable because it is not obvious what selector you are mocking.</p>
  
  <p>Opt 1: Mock Store using subject: impossible to know which selector the subject corresponds to, can't return different values for different selectors. </p>
  
  <p>// service.spec.ts</p>
  
  <pre><code>const selectSubject = new BehaviourSubject(null);
  class MockStore {
      select = () =&gt; selectSubject;
  }
  </code></pre>
  
  <p>Opt 2: Mock Store using switch: works for different selectors, but cannot make it work when the selectors have parameters.</p>
  
  <p>// service.spec.ts</p>
  
  <pre><code>    // This works well but how can I make it work with selectors with parameters??
      const firstSubject = new BehaviourSubject(null);
      const secondSubject = new BehaviourSubject(null);
      class MockStore {
          select = (selector) =&gt; {
              switch (selector): {
                  case FirstSelector: {
                      return firstSubject;
                  }
                  case SecondSelector: {
                      return secondSubject;
                  }
               }
          };
      }
  
      describe('TestService', () =&gt; {
          let service: TestService;
          let store: Store&lt;any&gt;;
  
          beforeEach(() =&gt; {
              TestBed.configureTestingModule({
                providers: [
                  TestService,
                  { provide: Store, useClass: MockStore }
                ],
              });
  
              service = TestBed.get(TestService);
              store = TestBed.get(Store);
            });
  
            it('should do X when first selector returns A and second selector returns B', () =&gt; {
              firstSelectorSubject.next(A);
              secondSelectorSubject.next(B);
  
          // Write expectation
            });
      });
  </code></pre>
  
  <p>Service method with parametrized selector I want to mock, so I can test getUserName with different id values</p>
  
  <pre><code>getUserName(id: string): Observable&lt;string&gt; {
      return this.store.select(getUser(id)).pipe(
        filter(user =&gt; user !== null),
        map(user =&gt; user.fullName)
      );
    }
  </code></pre>