我有一个方法,它接收一些值作为参数,然后调度一个操作。问题是,当我浅化组件来测试此方法时,出现错误,指出调度不是函数。
测试:
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}})
}
有人可以帮助我吗?我不知道我做错了什么。 提前致谢!
最佳答案
好的,现在我有这个测试:
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 吗?
关于javascript - 类型错误 : dispatch is not a function when I try to test a method using JEST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45935922/