Skip to content

Commit ca1be67

Browse files
EskiMojo14markerikson
authored andcommitted
add equalityFn test
1 parent e0da9c1 commit ca1be67

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/hooks/useSelector.spec.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type {
2626
} from '../../src/index'
2727
import type { FunctionComponent, DispatchWithoutAction, ReactNode } from 'react'
2828
import type { Store, AnyAction } from 'redux'
29-
import { StabilityCheck, UseSelectorOptions } from '../../src/hooks/useSelector'
29+
import { UseSelectorOptions } from '../../src/hooks/useSelector'
3030

3131
// most of these tests depend on selectors being run once, which stabilityCheck doesn't do
3232
// rather than specify it every time, let's make a new "default" here
@@ -757,8 +757,8 @@ describe('React', () => {
757757
selector,
758758
options,
759759
}: {
760-
selector: (state: NormalStateType) => number
761-
options?: UseSelectorOptions<number>
760+
selector: (state: NormalStateType) => unknown
761+
options?: UseSelectorOptions<unknown>
762762
}) => {
763763
useSelector(selector, options)
764764
return null
@@ -800,6 +800,23 @@ describe('React', () => {
800800
})
801801
)
802802
})
803+
it('uses provided equalityFn', () => {
804+
const unstableSelector = jest.fn((state: NormalStateType) => ({
805+
count: state.count,
806+
}))
807+
808+
rtl.render(
809+
<Provider store={normalStore}>
810+
<RenderSelector
811+
selector={unstableSelector}
812+
options={{ equalityFn: shallowEqual }}
813+
/>
814+
</Provider>
815+
)
816+
817+
expect(unstableSelector).toHaveBeenCalledTimes(2)
818+
expect(consoleSpy).not.toHaveBeenCalled()
819+
})
803820
it('by default will only check on first selector call', () => {
804821
rtl.render(
805822
<Provider store={normalStore}>

0 commit comments

Comments
 (0)