Skip to content

Commit

Permalink
Merge pull request #328 from stevoland/submit
Browse files Browse the repository at this point in the history
Tests for submit function being called
  • Loading branch information
erikras committed Nov 24, 2015
2 parents 4534422 + 9bc0f74 commit 98f466f
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion src/__tests__/createReduxForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint react/no-multi-comp:0*/
import expect from 'expect';
import React, {Component} from 'react';
import React, {Component, PropTypes} from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import {combineReducers, createStore} from 'redux';
Expand Down Expand Up @@ -586,4 +586,79 @@ describe('createReduxForm', () => {
readonly: true
});
});

it('should call onSubmit prop', (done) => {
const submit = (values) => {
expect(values).toEqual({
foo: undefined,
bar: undefined
});
done();
};

class FormComponent extends Component {
render() {
return (
<form onSubmit={this.props.handleSubmit} />
);
}
}
FormComponent.propTypes = {
handleSubmit: PropTypes.func.isRequired
};

const store = makeStore();
const form = 'testForm';
const Decorated = reduxForm({
form,
fields: ['foo', 'bar'],
readonly: true
})(FormComponent);
const dom = TestUtils.renderIntoDocument(
<Provider store={store}>
<Decorated onSubmit={submit} />
</Provider>
);
const button = TestUtils.findRenderedDOMComponentWithTag(dom, 'form');

TestUtils.Simulate.submit(button);
});

it('should call submit function passed to handleSubmit', (done) => {
const submit = (values) => {
expect(values).toEqual({
foo: undefined,
bar: undefined
});
done();
};

class FormComponent extends Component {
render() {
return (
<form onSubmit={this.props.handleSubmit(submit)} />
);
}
}

FormComponent.propTypes = {
handleSubmit: PropTypes.func.isRequired
};

const store = makeStore();
const form = 'testForm';
const Decorated = reduxForm({
form,
fields: ['foo', 'bar'],
readonly: true
})(FormComponent);
const dom = TestUtils.renderIntoDocument(
<Provider store={store}>
<Decorated />
</Provider>
);
const button = TestUtils.findRenderedDOMComponentWithTag(dom, 'form');

TestUtils.Simulate.submit(button);
});
});

0 comments on commit 98f466f

Please sign in to comment.