title: Jest mock submodule function
body: <p>I have this node module called <code>client</code>. It has the following structure:</p>
  
  <pre><code>//index.js
  import users from "./users"
  
  export default { users }
  </code></pre>
  
  <p>And: </p>
  
  <pre><code>//users.js
  export default { getUser }
  function getUser(username) {
      ...
      return {role: userRole}  
  }
  </code></pre>
  
  <p>I want to mock this getUser(username) function in my tests.
  So I could call something like:</p>
  
  <pre><code>client.users.getUser.mockResolvedValueOnce({role: "manager"}) 
  </code></pre>
  
  <p>My test header is like:</p>
  
  <pre><code>let client = jest.genMockFromModule('client').default;
  client.users.getUser = jest.fn();
  </code></pre>
  
  <p>But, running my test, I get the following error when my original code call <code>client.users.getUser</code>.</p>
  
  <blockquote>
  <pre><code>TypeError: Cannot read property 'users' of undefined
  
    58 | 
    59 |     // Retrieve user and then return its projects
  &gt; 60 |     client.users.getUser(username)
       |                  ^
    61 |         .then(user =&gt; {
    62 |             if (!user) {
    63 |                 throw new Error(`User ${username} not found`)
  
    at Object.getUser (node_modules/client/build/users.js:26:45)
    at Object.getUser [as insert] (src/web/controller/projects.js:60:18)
    at Object.insert (src/web/controller/projects.test.js:80:18)
  </code></pre>
  </blockquote>