我有一个方法接收一些值作为参数,然后调度一个动作。问题是,当我浅薄我的组件来测试这个方法时,我有一个错误,说dispatch不是一个函数。
TEST:
test('it changes the state when submit is clicked', () => {
const wrapper = shallow(<WizardForm store={store}/>);
const values = {
entrySign: 'archivoSign',
signCertificateFile: 'file',
signCertificate: 'text',
entryAuth: 'notArchivoAuth',
authCertificateFile: 'file',
authCertificate: 'text'
}
const form = wrapper.instance();
//in this method I get the error
form.submit(values)
方法:
submit(values) {
var authCertificate = this.checkAuth(values);
var signCertificate = this.checkSign(values);
let req = {
authCertificate: authCertificate,
signCertificate: signCertificate,
userId: this.state.userId
}
const { dispatch } = this.props
dispatch({type: 'CERTIFICATES_FETCH_REQUESTED', payload: {req}})
}
任何人都可以帮助我吗?我不知道我做错了什么。 提前谢谢!
答案 0 :(得分:0)
好的,现在我有了这个测试:
it('works', () => {
const values = {
username: 'marc',
name: 'marc',
email: 'marc@hotmail.com',
entrySign: 'archivoSign',
signCertificateFile: 'file',
signCertificate: 'text',
entryAuth: 'notArchivoAuth',
authCertificateFile: 'file',
authCertificate: 'text'
}
const mapDispatchToProps = (dispatch) => ({
submit
});
const mockedStore = createMockStore();
const WizardFormWrapper = connect(reduxFormReducer, mapDispatchToProps)(WizardForm);
const wrapper = shallowWithStore(<WizardFormWrapper />, mockedStore);
wrapper.props().submit();
});
})
我现在遇到的问题是:ReferenceError:未定义提交 任何建议@RIYAJ KHAN?