@@ -5,46 +5,60 @@ import { createStore } from 'redux'
5
5
import { Provider as ProviderMock , connect } from '../../src/index'
6
6
import * as rtl from '@testing-library/react'
7
7
import '@testing-library/jest-dom/extend-expect'
8
+ import type { AnyAction } from 'redux'
8
9
9
10
describe ( 'React' , ( ) => {
10
11
describe ( 'connect' , ( ) => {
11
12
afterEach ( ( ) => rtl . cleanup ( ) )
12
13
13
14
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' } ,
21
36
}
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
30
40
}
31
- return newState
32
- } )
41
+ )
33
42
34
43
const mapStateSpy1 = jest . fn ( )
35
44
const renderSpy1 = jest . fn ( )
36
45
37
46
let component1StateList
38
47
39
- const component1Decorator = connect ( ( state ) => {
48
+ const component1Decorator = connect <
49
+ Omit < RootStateType , 'byId' > ,
50
+ unknown ,
51
+ unknown ,
52
+ RootStateType
53
+ > ( ( state ) => {
40
54
mapStateSpy1 ( )
41
55
42
56
return {
43
57
list : state . list ,
44
58
}
45
59
} )
46
60
47
- const component1 = ( props ) => {
61
+ const component1 = ( props : Omit < RootStateType , 'byId' > ) => {
48
62
const [ state , setState ] = React . useState ( { list : props . list } )
49
63
50
64
component1StateList = state . list
@@ -63,7 +77,15 @@ describe('React', () => {
63
77
const mapStateSpy2 = jest . fn ( )
64
78
const renderSpy2 = jest . fn ( )
65
79
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 ) => {
67
89
mapStateSpy2 ( )
68
90
69
91
return {
0 commit comments