Skip to content

Instantly share code, notes, and snippets.

@sseletskyy
Last active June 27, 2017 08:12
Show Gist options
  • Save sseletskyy/4b209eda33ac280813d62c0c76acd40e to your computer and use it in GitHub Desktop.
Save sseletskyy/4b209eda33ac280813d62c0c76acd40e to your computer and use it in GitHub Desktop.
How to test a control in redux-form
/*
This is an example of a test for a Control Component inside of Redux Form
*/
import React from 'react';
import ComponentToBeTested from '../ComponentToBeTested';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import { reduxForm } from 'redux-form';
import sinon from 'sinon';
describe('ComponentToBeTested', () => {
const store = configureStore()({
define: 'it according to your needs',
form: {
testForm: {
values: {
define: 'default values of redux-form'
}
}
}
});
const spy = sinon.spy();
const props = {
onChange: spy,
};
const ComponentWithProps = someProps => {
return <ComponentToBeTested {...props} />;
};
const ReduxForm = reduxForm({
form: 'testForm',
})(ComponentWithProps);
const wrapper = mount(
<Provider store={store}>
<ReduxForm />
</Provider>,
);
it(`should have a component X with name`, () => {
const expectedProp = '?';
const component = wrapper.find('put your component name here');
expect(component.node.props.name).toEqual(expectedProp);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment