Skip to content

Commit 7a74052

Browse files
committed
Keep connect tests from breaking
1 parent d0147c8 commit 7a74052

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

test/components/connect.spec.tsx

+30-24
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ describe('React', () => {
7676
type: string
7777
body: any
7878
}
79-
function stringBuilder(prev = '', action: ActionType) {
80-
return action.type === 'APPEND' ? prev + action.body : prev
79+
interface StringState {
80+
string: string
81+
}
82+
83+
function stringBuilder(state = { string: '' }, action: ActionType) {
84+
return action.type === 'APPEND'
85+
? { string: state.string + action.body }
86+
: state
8187
}
8288

8389
afterEach(() => rtl.cleanup())
@@ -155,9 +161,9 @@ describe('React', () => {
155161
return <Passthrough {...this.props} />
156162
}
157163
}
158-
const ConnectedContainer = connect((state) => ({ string: state }))(
159-
Container
160-
)
164+
const ConnectedContainer = connect((state: StringState) => ({
165+
string: state.string,
166+
}))(Container)
161167

162168
const tester = rtl.render(
163169
<ProviderMock store={store}>
@@ -192,9 +198,9 @@ describe('React', () => {
192198
TStateProps,
193199
unknown,
194200
unknown,
195-
string
201+
StringState
196202
>((state) => ({
197-
string: state,
203+
string: state.string,
198204
}))(Container)
199205

200206
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
@@ -236,9 +242,9 @@ describe('React', () => {
236242
TStateProps,
237243
unknown,
238244
unknown,
239-
string
245+
StringState
240246
>((state) => ({
241-
string: state,
247+
string: state.string,
242248
}))(Container)
243249

244250
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
@@ -529,7 +535,7 @@ describe('React', () => {
529535
}
530536

531537
const ConnectedInner = connect(
532-
(state) => ({ stateThing: state }),
538+
(state: StringState) => ({ stateThing: state.string }),
533539
{ doSomething },
534540
(stateProps, actionProps, parentProps: InnerPropsType) => ({
535541
...stateProps,
@@ -1196,8 +1202,8 @@ describe('React', () => {
11961202
ChildrenPropsType,
11971203
unknown,
11981204
unknown,
1199-
string
1200-
>((state) => ({ state }))(Child)
1205+
StringState
1206+
>((state) => ({ state: state.string }))(Child)
12011207

12021208
const { unmount } = rtl.render(
12031209
<ProviderMock store={store}>
@@ -1477,9 +1483,9 @@ describe('React', () => {
14771483
TStateProps,
14781484
TDispatchProps,
14791485
{},
1480-
string
1486+
StringState
14811487
>(
1482-
(state) => ({ string: state }),
1488+
(state) => ({ string: state.string }),
14831489
(dispatch) => ({ dispatch })
14841490
)(Container)
14851491

@@ -1538,7 +1544,7 @@ describe('React', () => {
15381544
}
15391545
type TOwnProps = ContainerPropsType
15401546
type TMergedProps = TOwnProps & TDispatchProps & TStateProps
1541-
type RootState = string
1547+
type RootState = StringState
15421548

15431549
class Container extends Component<TMergedProps> {
15441550
render() {
@@ -1552,7 +1558,7 @@ describe('React', () => {
15521558
TMergedProps,
15531559
RootState
15541560
>(
1555-
(state) => ({ string: state }),
1561+
(state) => ({ string: state.string }),
15561562
(dispatch: ReduxDispatch) => ({ dispatch }),
15571563
(
15581564
stateProps: { string: string },
@@ -1705,9 +1711,9 @@ describe('React', () => {
17051711
return <Passthrough {...this.props} />
17061712
}
17071713
}
1708-
const ConnectedContainer = connect((state) => {
1714+
const ConnectedContainer = connect((state: StringState) => {
17091715
mapStateCalls++
1710-
return state === 'aaa' ? { change: 1 } : {}
1716+
return state.string === 'aaa' ? { change: 1 } : {}
17111717
})(Container)
17121718

17131719
rtl.render(
@@ -2927,7 +2933,7 @@ describe('React', () => {
29272933
}
29282934

29292935
const ConnectedContainerA = connect(
2930-
(state) => ({ string: state }),
2936+
(state: StringState) => ({ string: state.string }),
29312937
() => ({}),
29322938
() => ({}),
29332939
// The `pure` option has been removed
@@ -2942,7 +2948,7 @@ describe('React', () => {
29422948
}
29432949

29442950
const ConnectedContainerB = connect(
2945-
(state) => ({ string: state }),
2951+
(state: StringState) => ({ string: state.string }),
29462952
() => ({}),
29472953
() => ({}),
29482954
// The `pure` option has been removed
@@ -2968,7 +2974,7 @@ describe('React', () => {
29682974

29692975
describe('Subscription and update timing correctness', () => {
29702976
it('should pass state consistently to mapState', () => {
2971-
type RootStateType = string
2977+
type RootStateType = StringState
29722978
const store: Store = createStore(stringBuilder)
29732979

29742980
rtl.act(() => {
@@ -2999,7 +3005,7 @@ describe('React', () => {
29993005
ContainerNoDisPatch,
30003006
ContainerOwnProps,
30013007
RootStateType
3002-
>((state) => ({ state }))(Container)
3008+
>((state) => ({ state: state.string }))(Container)
30033009

30043010
const childCalls: any[] = []
30053011

@@ -3020,9 +3026,9 @@ describe('React', () => {
30203026
RootStateType
30213027
>((state, parentProps) => {
30223028
childMapStateInvokes++
3023-
childCalls.push([state, parentProps.parentState])
3029+
childCalls.push([state.string, parentProps.parentState])
30243030
// The state from parent props should always be consistent with the current state
3025-
expect(state).toEqual(parentProps.parentState)
3031+
expect(state.string).toEqual(parentProps.parentState)
30263032
return {}
30273033
})(ChildContainer)
30283034

0 commit comments

Comments
 (0)