0

I'm trying to write a simple unit test to make sure if the form inside a react component dispatches the expected action on submit.

Code:

Form submit action inside the component which I'm trying to test:

   <form onSubmit={(values, dispatch) => {  
        store.dispatch(doSomething());
        handleSubmit(values, dispatch);
    }}>

Test:

test('Test', (t) => {
const TestForm = TestForm();//redux form
const dispatchSpy = sinon.spy();

const props = Object.assign({}, baseProps, {
    handleSubmit: (callback) => {
        callback({}, dispatchSpy);
    },
});
t.context.form = mount(<Provider store={store}><TestForm /></Provider>);
t.context.form.find('form').simulate('submit');
//TODO - assert

The problem here is I get the following error and I'm not able to figure out the issue:

TypeError: callback is not a function

Any thoughts on this? Thanks.

InquisitiveGirl
  • 667
  • 3
  • 12
  • 31

1 Answers1

0

Are you sure you want to test form dispatches the expected action on submit ? I feel like it's just rewriting the internal test of redux-form (which is already tested here : https://github.com/erikras/redux-form/blob/master/src/tests/Form.spec.js#L131-L-165 )

Vincent Taing
  • 3,283
  • 2
  • 18
  • 24