title: Jest mock unnable to pick up error throw?
body: <p>I have some code that calls an api. I am testing the functionality that is nested in try catches, and checking the correct behaviour happens when I throw an error with certain values.</p>
  
  <pre><code>async function createDeployment(namespace, config, name) {
    try {
      await k8sDeploymentApi.createNamespacedDeployment(namespace, config, true);
      console.log('Successful deployment');
      return Promise.resolve(true);
    } catch (e) {
      console.log(JSON.stringify(e));
      if (e.response.statusCode === HTTP_CONFLICT) {
        try {
          await k8sDeploymentApi.replaceNamespacedDeployment(name, namespace, config, true);
          console.log('Successfully replaced deployment');
          return Promise.resolve(true);
        } catch (error) {
          return Promise.reject(error);
        }
      }
      return Promise.reject(e);
    }
  }
  </code></pre>
  
  <p>I am mocking out the api calls node module here</p>
  
  <pre><code>var mockListNamespacedIngress;
  var mockCreateNamespacedDeployment;
  var mockReplaceNamespacedDeployment;
  jest.mock('@kubernetes/client-node', () =&gt; {
    mockListNamespacedIngress = jest.fn();
    mockCreateNamespacedDeployment = jest.fn();
    mockReplaceNamespacedDeployment = jest.fn();
    return {
      KubeConfig: jest.fn().mockImplementation(() =&gt; ({
        loadFromCluster: jest.fn(),
        loadFromDefault: jest.fn(),
        makeApiClient: () =&gt; ({
          listNamespacedIngress: mockListNamespacedIngress,
          createNamespacedDeployment: mockCreateNamespacedDeployment,
          replaceNamespacedDeployment: mockReplaceNamespacedDeployment,
        }),
      })),
    };
  });
  </code></pre>
  
  <p>And running the test here</p>
  
  <pre><code>    it.only('Should return a log of success if replaced deployment resolves', async () =&gt; {
        mockCreateNamespacedDeployment.mockRejectedValueOnce(() =&gt;
          Promise.reject(new Error({ response: { statusCode: 409 } })),
        );
  
        mockReplaceNamespacedDeployment.mockResolvedValueOnce(true);
  
        // When
        await expect(createDeployment()).resolves.toEqual(true);
      });
  </code></pre>
  
  <p>However on the console.log(JSON.stringify(e)), I am only ever getting undefined coming back. So it does seem to throw the error, but gives no error object from the catch. Here is my full stacktrace</p>
  
  <pre><code> ● Kubernetes deployment script tests › Kubernetes Calls › Should return a log of success if replaced deployment resolves
  
      expect(received).resolves.toEqual()
  
      Received promise rejected instead of resolved
      Rejected to value: [TypeError: Cannot read property 'statusCode' of undefined]
  
        143 |
        144 |       // When
      &gt; 145 |       await expect(createDeployment()).resolves.toEqual(true);
            |             ^
        146 |     });
        147 |   });
        148 |
  
        at expect (node_modules/expect/build/index.js:134:15)
        at Object.it.only (src/__tests__/index.test.js:145:13)
  
    console.log
      Successful deployment
  
        at createDeployment (src/index.js:73:13)
  
    console.log
      undefined
  
        at createDeployment (src/index.js:76:13)
  </code></pre>