[react-redux] extended ThunkActionCreator testsuite to check all overloads

This commit is contained in:
Boris Sergeyev
2018-11-26 23:46:20 +01:00
parent 2d5a8af9f8
commit 9fa2b6599f
+54 -5
View File
@@ -120,12 +120,61 @@ function MapDispatchWithThunkActionCreators() {
}
class TestComponent extends React.Component<TestComponentProps> {}
const Test = connect(
null,
({ simpleAction, thunkAction }),
)(TestComponent);
const mapStateToProps = ({ foo }: { foo: string }) => ({ foo });
const mapDispatchToProps = { simpleAction, thunkAction };
const verify = <Test foo='bar' />;
const Test1 = connect(null, mapDispatchToProps)(TestComponent);
const Test2 = connect(mapStateToProps, mapDispatchToProps)(TestComponent);
const Test3 = connect(
null, mapDispatchToProps, null, { storeKey: 'somekey' }
)(TestComponent);
const Test4 = connect(
mapStateToProps, mapDispatchToProps, null, { storeKey: 'somekey' }
)(TestComponent);
const verify = <div>
<Test1 foo='bar' />;
<Test2 />
<Test3 foo='bar' />;
<Test4 />
</div>;
}
function MapManualDispatchThatLooksLikeThunk() {
interface OwnProps {
foo: string;
}
interface TestComponentProps extends OwnProps {
remove: (item: string) => () => object;
}
class TestComponent extends React.Component<TestComponentProps> {
render() {
return <div onClick={this.props.remove('someid')} />;
}
}
const mapStateToProps = ({ foo }: { foo: string }) => ({ foo });
function mapDispatchToProps(dispatch: Dispatch) {
return {
remove(item: string) {
return () => dispatch({ type: 'REMOVE_ITEM', item });
}
};
}
const Test1 = connect(null, mapDispatchToProps)(TestComponent);
const Test2 = connect(mapStateToProps, mapDispatchToProps)(TestComponent);
const Test3 = connect(
null, mapDispatchToProps, null, { storeKey: 'somekey' }
)(TestComponent);
const Test4 = connect(
mapStateToProps, mapDispatchToProps, null, { storeKey: 'somekey' }
)(TestComponent);
const verify = <div>
<Test1 foo='bar' />;
<Test2 />
<Test3 foo='bar' />;
<Test4 />
</div>;
}
function MapStateAndDispatchObject() {