Skip to content

Commit 3b2a4c5

Browse files
committed
refactor: transform test/components/hooks to tsx
1 parent f1201de commit 3b2a4c5

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

test/components/hooks.spec.js test/components/hooks.spec.tsx

+42-20
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,60 @@ import { createStore } from 'redux'
55
import { Provider as ProviderMock, connect } from '../../src/index'
66
import * as rtl from '@testing-library/react'
77
import '@testing-library/jest-dom/extend-expect'
8+
import type { AnyAction } from 'redux'
89

910
describe('React', () => {
1011
describe('connect', () => {
1112
afterEach(() => rtl.cleanup())
1213

1314
it('should render on useEffect hook state update', () => {
14-
const store = createStore((state, action) => {
15-
let newState =
16-
state !== undefined
17-
? state
18-
: {
19-
byId: {},
20-
list: [],
15+
interface RootStateType {
16+
byId: {
17+
[x: string]: string
18+
}
19+
list: Array<number>
20+
}
21+
const store = createStore<RootStateType, AnyAction, unknown, unknown>(
22+
(state, action) => {
23+
let newState =
24+
state !== undefined
25+
? state
26+
: {
27+
byId: {},
28+
list: [],
29+
}
30+
switch (action.type) {
31+
case 'FOO':
32+
newState = {
33+
...newState,
34+
list: [1],
35+
byId: { 1: 'foo' },
2136
}
22-
switch (action.type) {
23-
case 'FOO':
24-
newState = {
25-
...newState,
26-
list: [1],
27-
byId: { 1: 'foo' },
28-
}
29-
break
37+
break
38+
}
39+
return newState
3040
}
31-
return newState
32-
})
41+
)
3342

3443
const mapStateSpy1 = jest.fn()
3544
const renderSpy1 = jest.fn()
3645

3746
let component1StateList
3847

39-
const component1Decorator = connect((state) => {
48+
const component1Decorator = connect<
49+
Omit<RootStateType, 'byId'>,
50+
unknown,
51+
unknown,
52+
RootStateType
53+
>((state) => {
4054
mapStateSpy1()
4155

4256
return {
4357
list: state.list,
4458
}
4559
})
4660

47-
const component1 = (props) => {
61+
const component1 = (props: Omit<RootStateType, 'byId'>) => {
4862
const [state, setState] = React.useState({ list: props.list })
4963

5064
component1StateList = state.list
@@ -63,7 +77,15 @@ describe('React', () => {
6377
const mapStateSpy2 = jest.fn()
6478
const renderSpy2 = jest.fn()
6579

66-
const component2Decorator = connect((state, ownProps) => {
80+
interface Component2PropsType {
81+
mappedProp: Array<string>
82+
}
83+
const component2Decorator = connect<
84+
Component2PropsType,
85+
unknown,
86+
Omit<RootStateType, 'byId'>,
87+
RootStateType
88+
>((state, ownProps) => {
6789
mapStateSpy2()
6890

6991
return {

0 commit comments

Comments
 (0)