开玩笑地测试连接的Redux容器组件

时间:2019-07-09 05:24:34

标签: unit-testing react-native redux jestjs connect

import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as CommonActions from 'common/actions/common.actions';
import Activity from './activity.component';
const mapStateToProps = ({ common }) => ({common});
const mapDispatchToProps = dispatch => bindActionCreators(
{
getNationalities: CommonActions.getNationalities,
},dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(Activity);

如何测试这样的包含mapStateToPropsmapDispatchToPropsconnect的容器组件?

1 个答案:

答案 0 :(得分:1)

React-test-render可以测试组件,您必须导入包含mapStateToPropsmapDispatchToProps的组件。

示例:

<YourComponentName
 common={jest.fn()}
 getNationalities={jest.fn()}
/>