0
votes

I'm new in React and I try to apply this http://redux-form.com/5.2.5/#/getting-started?_k=vz58jr start form to my component, but there is problem:

Uncaught Invariant Violation: Could not find "store" in either the context or props of "Connect(ReduxForm(ContactForm))". Either wrap the root component in a , or explicitly pass "store" as a prop to "Connect(ReduxForm(ContactForm))".

what can I do with this?

3

3 Answers

2
votes

I have used redux-mock-store, react-redux, enzyme and chai.

For example:

singup

class Signup extends Component { ... }

Signup = reduxForm({
  form: 'newUser',
  fields: ['email', 'password', 'confirmPassword']
})(Signup);

Signup = connect(null, actions)(Signup);

export default Signup;

signup.test

import React from 'react';
import { shallow, mount } from 'enzyme';
import { expect } from 'chai';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import Signup from '../src/components/signup';

let wrapper;
const mockStore = configureStore([]);
const store = mockStore({});

describe('Signup', () => {

  beforeEach(() => {
      wrapper = mount(
        <Provider store={store}>
            <Signup />
        </Provider>
      );
  });

  it ('should have signup className', () => {
    expect(wrapper.find('.signup')).to.have.length(1);
  });

});
1
votes

I believe you need to pass the store down with provider. Here is a github repo I've got with redux-form working: https://github.com/joshuaslate/mern-starter/blob/master/client/src/index.js#L34

Here is a video on passing the store down with provider: https://egghead.io/lessons/javascript-redux-passing-the-store-down-with-provider-from-react-redux

0
votes

All those examples are wrapped with Provider. How to set up a Redux store is out of scope of the redux-form documentation. Follow the links Joshua posted to learn about that.