Skip to content

Commit

Permalink
add one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirShintel committed Nov 3, 2024
1 parent a04c04e commit 874082f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/connectWithShell.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ describe('connectWithShell-useCases', () => {
expect(renderSpy).toHaveBeenCalledTimes(2)
})

it('should clear state memoization on every state update when deferring subscriber notifications', async () => {
it('should clear state memoization on dispatch when deferring notifications and setting shouldClearMemoizedForState', async () => {
const { host, shell } = createMocks(entryPointWithState, [entryPointSecondStateWithAPI])
let numberOfCalls = 0
const originalFn = jest.fn(() => ++numberOfCalls)
Expand All @@ -951,6 +951,20 @@ describe('connectWithShell-useCases', () => {
expect(clearCacheSpy).toHaveBeenCalledTimes(1)
})

it('should not clear state memoization on dispatch when deferring notifications without setting shouldClearMemoizedForState', async () => {
const { host, shell } = createMocks(entryPointWithState, [entryPointSecondStateWithAPI])
let numberOfCalls = 0
const originalFn = jest.fn(() => ++numberOfCalls)
const memoizedFn = shell.memoizeForState(originalFn, () => '*') as _.MemoizedFunction
const clearCacheSpy = jest.spyOn(memoizedFn.cache, 'clear')

await host.getStore().deferSubscriberNotifications(() => {
host.getStore().dispatch({ type: 'MOCK' })
})

expect(clearCacheSpy).toHaveBeenCalledTimes(0)
})

it('should not mount connected component on props update', () => {
const { host, shell, renderInShellContext } = createMocks(entryPointWithState, [entryPointSecondStateWithAPI])
const ConnectedComp = connectWithShell(mapStateToProps, undefined, shell, { allowOutOfEntryPoint: true })(PureComp)
Expand Down

0 comments on commit 874082f

Please sign in to comment.