You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The overrideSelector method of MockStore sets the value on the memoized selector itself using setResult when not using a string. This values will leak between tests regardless of whether the TestBed is torn down or not since the memoized selector is only imported once per test suite.
import{someSelector}from'./selectors';// Test 1mockStore.overrideSelector(someSelector,10);// calls someSelector.setResult(10)// Reset TestBedtestBed.resetTestEnvironment();// The imported memoized selector is not touched by this.// Test 2mockStore.select(someSelector);// simply retrieves the result in selector (10)
This can be remedied by manually calling resetSelectors on the MockStore since that calls release and clearResult for every selector.
It seems the migration guide is incorrect and that this implication of overrideSelector is undocumented.
I would be willing to submit a PR to fix this issue
Yes
No
The text was updated successfully, but these errors were encountered:
The problem occurs when relying on Angular to teardown the Store.
While doing so, resetSelectors loses its context and cannot reset previously set selectors.
Yes, I realize this. However, the migration guide suggests that the behavior is somehow different or a non-issue when using destroyAfterEach. It seems to me that simply isn't true? As far as I can tell this has no bearing on whether or not you need to reset selectors. I'm only asking if it wouldn't make sense to update the migration guide since I think the current version is unclear at best. It might even be incorrect.
Which @ngrx/* package(s) are the source of the bug?
store
Minimal reproduction of the bug/regression with instructions
Reproduction in sbarfurth/selector-reset-repro.
Run
ng test
to reproduce.Expected behavior
All tests pass.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)
NgRx: v18.0.1
Angular: v18.0.7
Node: v20.15.0
Browser: Chrome v126
OS: macOS Sonoma 14.5
Other information
The automagic reset of the
MockStore
was removed with v13 as a breaking change. The migration guide states that this is a non-issue for tests usingdestroyAfterEach
: https://ngrx.io/guide/migration/v13#testing-reset-mock-storeThe
overrideSelector
method ofMockStore
sets the value on the memoized selector itself usingsetResult
when not using a string. This values will leak between tests regardless of whether theTestBed
is torn down or not since the memoized selector is only imported once per test suite.This can be remedied by manually calling
resetSelectors
on theMockStore
since that callsrelease
andclearResult
for every selector.It seems the migration guide is incorrect and that this implication of
overrideSelector
is undocumented.I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: