'Jest - Testing the onSubmit function of redux-form
I would like to test the onSubmit function of a reudx-form. Here is how it looks
class ConfigurationEditForm extends Component {
render(){
const { handleSubmit } = this.props
return(
<form onSubmit={handleSubmit}>
<Grid container>
<Grid item xs={12}>
<Field
component={TextField}
type='text'
floatingLabelText='Configuration Name'
name='key'
/>
</Grid>
<Grid item xs={12}>
<Field
component={TextField}
type='text'
floatingLabelText='Configuration Value'
name='value'
/>
</Grid>
</Grid>
</form>
)
}
}
ConfigurationEditForm = reduxForm({
form: "configurationEditForm ",
onSubmit: (values, dispatch, props) => {
props.submitCallback(values);
}
})(ConfigurationEditForm);
However, when it comes to testing the form, I do the following in Jest:
var payload = JSON.stringify({name: "test", value: "12"})
const store = mockStore({});
let wrapper = shallow(<ConfigurationEditForm store={store} submitCallback={jest.fn()}/>);
wrapper.simulate("submit", {payload: payload})
The error I get is TypeError: Cannot read property 'submitCallback' of undefined
I've been researching this but cannot find any hints.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
