Leff
Leff

Reputation: 1320

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:

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

I am passing a submitValidation function to a redux form handleSubmit function like this:

<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

Why am I getting this error, when also on the inspecting the formProps in the console I can see that handleSubmit is a function. How can I make this test pass?

Upvotes: 0

Views: 302

Answers (1)

Maciej Wojsław
Maciej Wojsław

Reputation: 403

If you're using rest operator the last parameter will have a type of Array, try to remove spread from UttakInfoPanel component.

Upvotes: 1

Related Questions