Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricduffournet committed Dec 2, 2021
1 parent 14b2413 commit 26d4749
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions modules/store/testing/spec/mock_store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Store,
createSelector,
select,
StoreModule,
MemoizedSelector,
createFeatureSelector,
isNgrxMockEnvironment,
Expand Down Expand Up @@ -515,3 +516,53 @@ describe('Refreshing state', () => {
expect(getTodoItems('li')[0].nativeElement.textContent.trim()).toBe('bbb');
});
});

describe('Cleanup selectors after each test', () => {
let store: MockStore;
const selectData = createSelector(
(state: any) => state,
(state) => state.value
);

// see https://github.com/ngrx/platform/issues/3243
afterEach(() => {
store.resetSelectors();
});

it('should return the mocked selectors value', (done: any) => {
TestBed.configureTestingModule({
providers: [
provideMockStore({
initialState: {
value: 100,
},
selectors: [{ selector: selectData, value: 200 }],
}),
],
});

store = TestBed.inject(MockStore);
store.pipe(select(selectData)).subscribe((v) => {
expect(v).toBe(200);
done();
});
});

it('should return the real value', (done: any) => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({} as any, {
initialState: {
value: 300,
},
}),
],
});

const store = TestBed.inject(Store);
store.pipe(select(selectData)).subscribe((v) => {
expect(v).toBe(300);
done();
});
});
});
2 changes: 1 addition & 1 deletion projects/ngrx.io/content/guide/store/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ In this example based on the [walkthrough](guide/store/walkthrough), we mock the

<div class="alert is-helpful">

**Note:** `MockStore` will reset all of the mocked selectors after each test (in the `afterEach()` hook) by calling the `MockStore.resetSelectors()` method.
**Note:** `MockStore` will **not** reset mocked selectors after each test. You can reset selectors by calling the `MockStore.resetSelectors()` method in `afterEach()` hook.

</div>

Expand Down

0 comments on commit 26d4749

Please sign in to comment.