Skip to content
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

wrap selector factories in createSelector.memoize (weakMapMemoize by default) #4164

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test memoize methods
  • Loading branch information
EskiMojo14 committed Feb 6, 2024
commit 77f040b59eb79b1e9b6b52f91fc489533050296f
23 changes: 23 additions & 0 deletions packages/toolkit/src/query/tests/buildSelector.test.ts
Original file line number Diff line number Diff line change
@@ -37,4 +37,27 @@ describe('buildSelector', () => {
exampleApi.endpoints.getTodos.select('1')(store.store.getState()),
).toBe(exampleApi.endpoints.getTodos.select('1')(store.store.getState()))
})
it('exposes memoize methods on select', () => {
expect(exampleApi.endpoints.getTodos.select.resultsCount).toBeTypeOf(
'function',
)
expect(exampleApi.endpoints.getTodos.select.resetResultsCount).toBeTypeOf(
'function',
)
expect(exampleApi.endpoints.getTodos.select.clearCache).toBeTypeOf(
'function',
)

const firstResult = exampleApi.endpoints.getTodos.select('1')

exampleApi.endpoints.getTodos.select.clearCache()

const secondResult = exampleApi.endpoints.getTodos.select('1')

expect(firstResult).not.toBe(secondResult)

expect(firstResult(store.store.getState())).not.toBe(
secondResult(store.store.getState()),
)
})
})
Loading