-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clear lastResult between tests #569
Comments
This actually works for me... what doesnt work for me is using the
Also the export const getEscrowsByCategory = createSelector(
[
getEscrows,
(_state: CommonReducerShape, escrowCateorgy: EscrowRequestCategory) =>
escrowCateorgy,
],
(escrowsById, escrowCategory) =>
Object.values(escrowsById).filter(escrow =>
escrowCategoryToStateMap[escrowCategory].includes(escrow.state),
),
{
memoizeOptions: {
equalityCheck: isEqual,
maxSize: Object.keys(EscrowRequestCategory).length,
},
},
)
// Unit test
beforeEach(() => {
// does not clear cache but is on the type definition :(
// getEscrowsByCategory.clearCache()
// works but is not on type definition of `memoizedResultFunc`
;(
getEscrowsByCategory.memoizedResultFunc as unknown as typeof getEscrowsByCategory
).clearCache()
// this works great though :)
getEscrowsByCategory.resetRecomputations()
}) |
@alexburkowskypolysign Hmm. |
@markerikson see the type error here: https://codesandbox.io/s/tender-lederberg-l1d1jr?file=/src/index.ts And update to my previous comment - the type issue seems to hold true for selectors created without memoization options as well per the codesandbox The method itself I believe IS on both functions in JS land (console.log says both are Functions) although I cant get it to work in tests without accessing I think its because the generic argument Line 30 in 2f892bb
Is it intended that https://github.com/reduxjs/reselect#defaultmemoizefunc-equalitycheckoroptions--defaultequalitycheck
My concern overall is mostly with the type definitions, I kinda dont have a need for |
Uh... this is really bizarre, because TS says it should be there as part of the typedef of
As far as the runtime behavior: the issue here is that |
Makes sense this should probably be clarified in the README To add to the weirdness @markerikson - I cannot get Maybe im using it incorrectly in the sandbox but correctly in my IDE? |
Is it possible TS is reading that additional |
Maybe? Unfortunately this isn't something I really have much time to look into in the near future. If you can identify an issue with the types or runtime behavior, definitely interested in anything we can fix. |
I dont have a ton of time until probs end of the week. Im definitely happy to look into the type issue and put up a PR. The cache issue (if it is an issue) may be over my head. If anyone else here that has worked on the core codebase has any thoughts on the issue in the codesandbox, additional input would be appreciated |
The cache issue, maybe is not an issue, can be fixed when you run "getEscrowsByCategory.clearCache()" as well as "getEscrowsByCategory.memoizedResultFunc.clearCache()" before "getEscrowsByCategory(state, "category");": ` console.log( Because when I'm sorry that I'm not good at English, hope you can understand what I'm saying. |
I think this one can be closed, just need to call |
I'm facing the same issue, this works but needs to be applied to each selector
Has anyone come up with a stable Jest mock to prevent memoization? |
I have a selector which looks at the lastResult value and decides whether it needs to recalculate.
the problem is I can't find a way to clear this value between tests.
I'm running
selector.memoizedResultFunc.clearCache()
in beforeEach but it doesn't seem to helpThe text was updated successfully, but these errors were encountered: