title: How to test a component using react-redux hooks?
body: <p>I have a simple Todo component that utilizes react-redux hooks that I'm testing using enzyme but I'm getting either an error or an empty object with a shallow render as noted below. </p>
  
  <p>What is the correct way to test components using hooks from react-redux?</p>
  
  <p><strong>Todos.js</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>const Todos = () =&gt; {
    const { todos } = useSelector(state =&gt; state);
  
    return (
      &lt;ul&gt;
        {todos.map(todo =&gt; (
          &lt;li key={todo.id}&gt;{todo.title}&lt;/li&gt;
        ))}
      &lt;/ul&gt;
    );
  };
  </code></pre>
  
  <p><strong>Todos.test.js</strong> v1</p>
  
  <pre class="lang-js prettyprint-override"><code>...
  
  it('renders without crashing', () =&gt; {
    const wrapper = shallow(&lt;Todos /&gt;);
    expect(wrapper).toMatchSnapshot();
  });
  
  it('should render a ul', () =&gt; {
    const wrapper = shallow(&lt;Todos /&gt;);
    expect(wrapper.find('ul').length).toBe(1);
  });
  </code></pre>
  
  <p>v1 Error:</p>
  
  <pre><code>...
  Invariant Violation: could not find react-redux context value; 
  please ensure the component is wrapped in a &lt;Provider&gt;
  ...
  </code></pre>
  
  <p><strong>Todos.test.js</strong> v2</p>
  
  <pre class="lang-js prettyprint-override"><code>...
  // imported Provider from react-redux 
  
  it('renders without crashing', () =&gt; {
    const wrapper = shallow(
      &lt;Provider store={store}&gt;
        &lt;Todos /&gt;
      &lt;/Provider&gt;,
    );
    expect(wrapper).toMatchSnapshot();
  });
  
  it('should render a ul', () =&gt; {
    const wrapper = shallow(&lt;Provider store={store}&gt;&lt;Todos /&gt;&lt;/Provider&gt;);
    expect(wrapper.find('ul').length).toBe(1);
  });
  </code></pre>
  
  <p>v2 tests also fail since <code>wrapper</code> is the <code>&lt;Provider&gt;</code> and calling <code>dive()</code> on <code>wrapper</code> will return the same error as v1.</p>
  
  <p>Thanks in advance for your help!</p>