8

I am trying to create unit testing with jest in angular 8 with RXJS. I want to mock store. I am using https://ngrx.io/guide/store/testing example of Using Mock Selectors. could anyone help me to how can I use MemoizedSelector and MockStore to use mock the store independently.

 this.store.select(homeState).pipe(select(s => s.checkStatus)).subscribe(status => {
     console.log(status);
     // We performation other action.
});

I have many selectors in this component. how can I mock many selectors and update the selector's value for each test case?

Jitendra
  • 286
  • 1
  • 2
  • 7

1 Answers1

7

You should follow their info in Using Mock Selectors.

describe('User Greeting Component', () => { 
  beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [provideMockStore()],
      declarations: [YourComponent],
    }); 
  });

  it('test', () => {
    const mockStore = TestBed.inject(MockStore);
    const mockHomeState = mockStore.overrideSelector(
      homeState,
      {checkStatus: true}
    );

    const fixture = TestBed.createComponent(YourComponent);
    fixture.detectChanges();
  });
});
satanTime
  • 12,631
  • 1
  • 25
  • 73