简体   繁体   English

测试Redux表单失败-typeError formProps.handleSubmit不是函数

[英]Testing redux form fails - typeError formProps.handleSubmit is not a function

I have a component where I use redux form to which I pass redux form props like this: 我有一个组件,我在其中使用redux表单,并向其中传递redux表单道具:

export const UttakInfoPanel = ({
  submitValidation,
  ...formProps
})

I am passing a submitValidation function to a redux form handleSubmit function like this: 我正在将submitValidation函数传递给redux表单的handleSubmit函数,如下所示:

<form onSubmit={formProps.handleSubmit(submitValidation)}>

Submit validation works fine. 提交验证工作正常。 I have also made a test for that component: 我还对该组件进行了测试:

it('will show InfoPanel', () => {
    const formProps = {
      handleSubmit: sinon.spy,
      error: {},
    };

    const wrapper = shallowWithIntl(<InfoPanel
      submitValidation={sinon.spy()}
      formProps={formProps}
    />);
  });

But, when I am running my test I get: 但是,当我运行测试时,我得到:

TypeError: formProps.handleSubmit is not a function TypeError:formProps.handleSubmit不是一个函数

Why am I getting this error, when also on the inspecting the formProps in the console I can see that handleSubmit is a function. 为什么formProps在控制台中检查formProps时看到此错误,所以我可以看到handleSubmit是一个函数。 How can I make this test pass? 我如何才能通过此考试?

如果您使用rest运算符,则最后一个参数将具有Array类型,请尝试从UttakInfoPanel组件中删除散布。

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

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