我想测试 submit()功能,但在搜索和阅读大量帖子后我不知道怎么做。
我发现了如何测试组件的生命周期方法,render()函数而不是submit()。我正在使用酶,sinon,jest进行测试。
export class ChangePassword extends React.Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
}
submit() {
const {dispatch} = this.props;
this.setState({clicked: true});
let userId = GeneralHelper.userId();
let {currentPassword, newPassword} = this.props.form.changePasswordForm.values;
let data = {
currentPassword,
newPassword
};
dispatch(changePassword(userId, data));
dispatch(reset('changePasswordForm'));
}
render() {
<ChangePasswordForm onSubmit={this.submit}/>
}
}
ChangePassword.propTypes = {};
ChangePassword.defaultProps = {};
const mapStateToProps = state => {
return state;
};
export default connect(mapStateToProps)(ChangePassword);