Skip to content

Commit 8d6f42b

Browse files
committed
Use React-compat stores in useSelector tests
1 parent 73495d2 commit 8d6f42b

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

test/hooks/useSelector.spec.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import {
2929
useSelector,
3030
} from 'react-redux'
3131
import type { Action, AnyAction, Store } from 'redux'
32-
import { createStore } from 'redux'
32+
// import { createStore } from 'redux'
33+
import { createTestStore } from '../testUtils'
3334

3435
// disable checks by default
3536
function ProviderMock<A extends Action<any> = AnyAction, S = unknown>({
@@ -60,7 +61,7 @@ describe('React', () => {
6061
const useNormalSelector: TypedUseSelectorHook<RootState> = useSelector
6162

6263
beforeEach(() => {
63-
normalStore = createStore(
64+
normalStore = createTestStore(
6465
({ count }: NormalStateType = { count: -1 }): NormalStateType => ({
6566
count: count + 1,
6667
}),
@@ -121,7 +122,7 @@ describe('React', () => {
121122

122123
describe('lifecycle interactions', () => {
123124
it('always uses the latest state', () => {
124-
const store = createStore((c: number = 1): number => c + 1, -1)
125+
const store = createTestStore((c: number = 1): number => c + 1, -1)
125126

126127
const Comp = () => {
127128
const selector = useCallback((c: number): number => c + 1, [])
@@ -251,7 +252,7 @@ describe('React', () => {
251252
})
252253

253254
it('works properly with memoized selector with dispatch in Child useLayoutEffect', () => {
254-
const store = createStore((c: number = 1): number => c + 1, -1)
255+
const store = createTestStore((c: number = 1): number => c + 1, -1)
255256

256257
const Comp = () => {
257258
const selector = useCallback((c: number): number => c, [])
@@ -293,7 +294,7 @@ describe('React', () => {
293294
describe('performance optimizations and bail-outs', () => {
294295
it('defaults to ref-equality to prevent unnecessary updates', () => {
295296
const state = {}
296-
const store = createStore(() => state)
297+
const store = createTestStore(() => state)
297298

298299
const Comp = () => {
299300
const value = useSelector((s) => s)
@@ -321,7 +322,7 @@ describe('React', () => {
321322
count: number
322323
stable: {}
323324
}
324-
const store = createStore(
325+
const store = createTestStore(
325326
({ count, stable }: StateType = { count: -1, stable: {} }) => ({
326327
count: count + 1,
327328
stable,
@@ -365,9 +366,11 @@ describe('React', () => {
365366
interface StateType {
366367
count: number
367368
}
368-
const store = createStore(({ count }: StateType = { count: 0 }) => ({
369-
count: count + 1,
370-
}))
369+
const store = createTestStore(
370+
({ count }: StateType = { count: 0 }) => ({
371+
count: count + 1,
372+
}),
373+
)
371374

372375
const selector = vi.fn((s: StateType) => {
373376
return s.count
@@ -401,9 +404,11 @@ describe('React', () => {
401404
interface StateType {
402405
count: number
403406
}
404-
const store = createStore(({ count }: StateType = { count: 0 }) => ({
405-
count: count + 1,
406-
}))
407+
const store = createTestStore(
408+
({ count }: StateType = { count: 0 }) => ({
409+
count: count + 1,
410+
}),
411+
)
407412

408413
const selector = vi.fn((s: StateType) => {
409414
return s.count
@@ -535,7 +540,9 @@ describe('React', () => {
535540
return <div>{result}</div>
536541
}
537542

538-
const store = createStore((count: number = -1): number => count + 1)
543+
const store = createTestStore(
544+
(count: number = -1): number => count + 1,
545+
)
539546

540547
const App = () => (
541548
<ProviderMock store={store}>
@@ -671,7 +678,7 @@ describe('React', () => {
671678
it('should have linear or better unsubscribe time, not quadratic', () => {
672679
const reducer = (state: number = 0, action: any) =>
673680
action.type === 'INC' ? state + 1 : state
674-
const store = createStore(reducer)
681+
const store = createTestStore(reducer)
675682
const increment = () => ({ type: 'INC' })
676683

677684
const numChildren = 100000
@@ -1070,12 +1077,16 @@ describe('React', () => {
10701077
}
10711078

10721079
beforeEach(() => {
1073-
defaultStore = createStore(({ count }: StateType = { count: -1 }) => ({
1074-
count: count + 1,
1075-
}))
1076-
customStore = createStore(({ count }: StateType = { count: 10 }) => ({
1077-
count: count + 2,
1078-
}))
1080+
defaultStore = createTestStore(
1081+
({ count }: StateType = { count: -1 }) => ({
1082+
count: count + 1,
1083+
}),
1084+
)
1085+
customStore = createTestStore(
1086+
({ count }: StateType = { count: 10 }) => ({
1087+
count: count + 2,
1088+
}),
1089+
)
10791090
})
10801091

10811092
it('subscribes to the correct store', () => {

0 commit comments

Comments
 (0)