title: Mock the constructor for AWS.DynamoDB.DocumentClient using jest
body: <p>I have a function that looks like this:</p>
  
  <pre><code>function connect() {
     const secret = 'secret';
     const key = 'key';
     const region = 'region';
     const client = new AWS.DynamoDB({
        secret,
        key,
        region
     });'
     return new AWS.DynamoDB.DocumentClient({ service: client })
  }
  </code></pre>
  
  <p>I would like to test the function connect. I have mocked the DynamoDB constructor like this:</p>
  
  <pre><code>// See https://stackoverflow.com/questions/47606545/mock-a-dependencys-constructor-jest
  jest.mock('aws-sdk', () =&gt; {
    const DynamoDB = jest.fn().mockImplementation(() =&gt; {
      return {};
    });
    return {
      DynamoDB,
    };
  });
  </code></pre>
  
  <p>However, this means that the <code>DocumentClient</code> constructor fails. How do I mock that as well?</p>