Skip to content

Commit 938b18e

Browse files
committed
refactor: transform test/integration/server-rendering => ts
1 parent 8f5b8c3 commit 938b18e

File tree

1 file changed

+49
-14
lines changed

1 file changed

+49
-14
lines changed

test/integration/server-rendering.spec.js renamed to test/integration/server-rendering.spec.tsx

+49-14
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,64 @@
88

99
/*eslint-disable react/prop-types*/
1010

11-
import React from 'react'
11+
import React, { FunctionComponent } from 'react'
1212
import { renderToString } from 'react-dom/server'
1313
import { createStore } from 'redux'
1414
import { Provider, connect } from '../../src/index'
15+
import type { Dispatch, Store } from 'redux'
1516

1617
describe('React', () => {
1718
describe('server rendering', () => {
18-
function greetingReducer(state = { greeting: 'Hello' }, action) {
19+
interface ActionType {
20+
type: string
21+
payload: {
22+
greeting: string
23+
}
24+
}
25+
function greetingReducer(
26+
state = { greeting: 'Hello' },
27+
action: ActionType
28+
) {
1929
return action && action.payload ? action.payload : state
2030
}
31+
interface GreetingProps {
32+
greeting: string
33+
greeted: string
34+
}
35+
const Greeting: FunctionComponent<GreetingProps> = ({
36+
greeting,
37+
greeted,
38+
}) => {
39+
return <span>{greeting + ' ' + greeted}</span>
40+
}
2141

22-
const Greeting = ({ greeting, greeted }) => greeting + ' ' + greeted
23-
const ConnectedGreeting = connect((state) => state)(Greeting)
42+
interface RootType {
43+
greeting: string
44+
}
45+
interface Props {
46+
greeted: string
47+
}
2448

25-
const Greeter = (props) => (
49+
const ConnectedGreeting = connect<RootType, unknown, Props, RootType>(
50+
(state) => state
51+
)(Greeting)
52+
53+
const Greeter = (props: any) => (
2654
<div>
2755
<ConnectedGreeting {...props} />
2856
</div>
2957
)
3058

31-
class Dispatcher extends React.Component {
32-
constructor(props) {
59+
interface DispatcherProps {
60+
constructAction?: ActionType
61+
willMountAction?: ActionType
62+
renderAction?: ActionType
63+
dispatch: Dispatch
64+
greeted: string
65+
}
66+
67+
class Dispatcher extends React.Component<DispatcherProps> {
68+
constructor(props: DispatcherProps) {
3369
super(props)
3470
if (props.constructAction) {
3571
props.dispatch(props.constructAction)
@@ -51,23 +87,22 @@ describe('React', () => {
5187
const ConnectedDispatcher = connect()(Dispatcher)
5288

5389
it('should be able to render connected component with props and state from store', () => {
54-
const store = createStore(greetingReducer)
90+
const store: Store = createStore(greetingReducer)
5591

5692
const markup = renderToString(
5793
<Provider store={store}>
5894
<Greeter greeted="world" />
5995
</Provider>
6096
)
61-
6297
expect(markup).toContain('Hello world')
6398
})
6499

65100
it('should run in an SSR environment without logging warnings about useLayoutEffect', () => {
66-
const store = createStore(greetingReducer)
101+
const store: Store = createStore(greetingReducer)
67102

68103
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
69104

70-
const markup = renderToString(
105+
renderToString(
71106
<Provider store={store}>
72107
<Greeter greeted="world" />
73108
</Provider>
@@ -79,7 +114,7 @@ describe('React', () => {
79114
})
80115

81116
it('should render with updated state if actions are dispatched before render', () => {
82-
const store = createStore(greetingReducer)
117+
const store: Store = createStore(greetingReducer)
83118

84119
store.dispatch({ type: 'Update', payload: { greeting: 'Hi' } })
85120

@@ -106,7 +141,7 @@ describe('React', () => {
106141
In all other versions, including v7, the store state may change as actions are dispatched
107142
during lifecycle methods, and components will see that new state immediately as they read it.
108143
*/
109-
const store = createStore(greetingReducer)
144+
const store: Store = createStore(greetingReducer)
110145

111146
const constructAction = { type: 'Update', payload: { greeting: 'Hi' } }
112147
const willMountAction = { type: 'Update', payload: { greeting: 'Hiya' } }
@@ -143,7 +178,7 @@ describe('React', () => {
143178
This test works both when state is fetched directly in connected
144179
components and when it is fetched in a Provider and placed on context
145180
*/
146-
const store = createStore(greetingReducer)
181+
const store: Store = createStore(greetingReducer)
147182

148183
const constructAction = { type: 'Update', payload: { greeting: 'Hi' } }
149184
const willMountAction = { type: 'Update', payload: { greeting: 'Hiya' } }

0 commit comments

Comments
 (0)