title: Jest/Enzyme Unit Testing: How to pass store to shallow component that uses redux 4 and react-redux 6 connect function
body: <p>I'm doing as usual some unit tests with jest and enzyme for one new project. I used to test components that were connected to redux in this way:</p>
  
  <p>a) a store generator</p>
  
  <pre><code>import { createStore } from 'redux';
  
  import rootReducer from '../src/reducers';
  
  export const storeFactory = (initialState) =&gt; {
     return createStore(rootReducer, initialState);
  }
  </code></pre>
  
  <p>which is consumed by the Input.test.js file</p>
  
  <pre><code>import React from 'react';
  import { shallow } from 'enzyme';
  
  import { findByTestAttr,storeFactory } from '../../../test/testUtils';
  import Input from './Input';
  
  
  
  const setup = (initialState={}) =&gt; {
      const store = storeFactory(initialState);
      const wrapper = shallow(
          &lt;Input store={store} /&gt;
          ).dive();
      console.log(wrapper.debug());
  
  }
  </code></pre>
  
  <p>being the example component Input.js: </p>
  
  <pre><code>import React, { Component } from 'react';
  import { connect } from 'react-redux';
  
  class Input extends Component {
      render(){
          return &lt;div /&gt;;
      }
  }
  
  const mapStateToProps = (state) =&gt; {
      return {};
  }
  
  export default connect(mapStateToProps)(Input);
  </code></pre>
  
  <p>My npm package versions are: </p>
  
  <pre><code> "dependencies": {
      "ajv": "^6.6.2",
      "react": "^16.7.0",
      "react-dom": "^16.7.0",
      "react-redux": "^6.0.0",
      "react-scripts": "2.1.3",
      "redux": "^4.0.1"
    }
  
    "devDependencies": {
      "check-prop-types": "^1.1.2",
      "enzyme": "^3.8.0",
      "enzyme-adapter-react-16": "^1.7.1",
      "jest": "^23.6.0",
      "jest-enzyme": "^7.0.1",
      "prop-types": "^15.6.2"
    }
  </code></pre>
  
  <p>And that used to work, but I'm getting this message when running the tests on the tests execution report: </p>
  
  <blockquote>
    <p>Invariant Violation: Passing redux store in props has been removed
    and does not do anything. To use a custom Redux store for specific
    components,  create a custom React context with React.createContext(),
    and pass the context object to React-Redux's Provider and specific
    components like:  . You may also pass a {context :
    MyContext} option to connect</p>
  </blockquote>
  
  <p>I tried to pass the context as a parameter of shallow</p>
  
  <pre><code>const setup = (initialState={}) =&gt; {
      const store = storeFactory(initialState);
      const wrapper = shallow(
          &lt;Input  /&gt;, { store }
          );
      console.log(wrapper.debug());
  
  }
  </code></pre>
  
  <p>But then I get this logged to console</p>
  
  <pre><code>&lt;ContextConsumer&gt;
          [function bound renderWrappedComponent]
        &lt;/ContextConsumer&gt;
  </code></pre>
  
  <p>and if I try to use then enzyme dive() method I get:</p>
  
  <pre><code>const setup = (initialState={}) =&gt; {
      const store = storeFactory(initialState);
      const wrapper = shallow(
          &lt;Input  /&gt;, { store }
          ).dive();
      console.log(wrapper.debug());
  
  }
  </code></pre>
  
  <blockquote>
    <p>Test suite failed to run</p>
  
  <pre><code>TypeError: ShallowWrapper::dive() can only be called on components
  </code></pre>
  </blockquote>
  
  <p>Which is the suggested way of doing it now? I know what the message says but before there was no need of wrapping the element into a Provider for jest/enzyme unit tests. Thank you very much!</p>