title: jest spyOn not working on index file, cannot redefine property
body: <p>I have <code>UserContext</code> and a hook <code>useUser</code> exported from <code>src/app/context/user-context.tsx</code>.
  Additionally I have an index.tsx file in <code>src/app/context</code> which exports all child modules.</p>
  <p>If I spyOn <code>src/app/context/user-context</code> it works but changing the import to <code>src/app/context</code> I get:</p>
  <pre><code>TypeError: Cannot redefine property: useUser at Function.defineProperty (&lt;anonymous&gt;)
  </code></pre>
  <p>Why is that?</p>
  <p>Source code:</p>
  <pre class="lang-js prettyprint-override"><code>// src/app/context/user-context.tsx
  
  export const UserContext = React.createContext({});
  
  export function useUser() {
    return useContext(UserContext);;
  }
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// src/app/context/index.tsx
  
  export * from &quot;./user-context&quot;;
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// *.spec.tsx
  
  // This works:
  import * as UserContext from &quot;src/app/context/user-context&quot;;
  
  // This does not work:
  // import * as UserContext from &quot;src/app/context&quot;;
  
  it(&quot;should render complete navigation when user is logged in&quot;, () =&gt; {
  
      jest.spyOn(UserContext, &quot;useUser&quot;).mockReturnValue({
          user: mockUser,
          update: (user) =&gt; null,
          initialized: true,
      });
  })
  </code></pre>