title: mock useSelector of react-redux with jest for test with react testing-library
body: <p>I'm trying to test a component that uses react-redux for state management.</p>
  <p>To test quickly I want to mock useSelector, like this:</p>
  <pre><code>const templates = [
    {
      id: ...,
      name: ...,
      ...
    },
    {
      id: ...,
      name: ...,
      ...
    },
  ]
  
  
  jest.mock('react-redux', () =&gt; ({
    ...jest.requireActual('react-redux'),
    useSelector: jest.fn(),
  }));
  
  
  describe('some awesome description', () =&gt; {
    beforeEach(() =&gt; {
      useSelector.mockImplementation(callback =&gt; callback(templates));
    });
  });
  </code></pre>
  <p>But when running the tests, this fails as follows:</p>
  <pre><code>TypeError: Cannot read properties of undefined (reading 'ids')
  
    141 | describe('layouts/TemplatesPanel', () =&gt; {
    142 |   beforeEach(() =&gt; {
  &gt; 143 |     useSelector.mockImplementation(callback =&gt; callback(templates));
        |                                                ^
  </code></pre>