繁体   English   中英

TypeError:当我尝试使用JEST测试方法时,dispatch不是函数

[英]TypeError: dispatch is not a function when I try to test a method using JEST

我有一个方法,该方法接收一些值作为参数,然后调度一个动作。 问题是,当我使组件变浅以测试此方法时,出现一个错误,指出dispatch不是函数。

测试:

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吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM