title: Jest automock not applied to a module
body: <p>I've run into trouble running Jest tests for my modules - I have a simple entry-point class:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { Callback, CloudFrontRequestEvent, Context, Handler } from "aws-lambda";
  
  import { CloudFrontHandler } from "./CloudFrontHandler";
  import { OriginClient } from "./OriginClient";
  import { ResponseRenderer } from "./ResponseRenderer";
  import { TemplateRenderer } from "./TemplateRenderer";
  
  export class LambdaHandler {
      private readonly renderer: TemplateRenderer;
  
      constructor(renderer: TemplateRenderer) {
          this.renderer = renderer;
      }
  
      public handle: Handler = (event: CloudFrontRequestEvent, _: Context, callback: Callback): void =&gt; {
          console.log(new CloudFrontHandler(null, null)); // &lt;- just an empty object here! CloudFrontHandler {}
          console.log(new OriginClient(null)); // &lt;- properly mocked
          console.log(new ResponseRenderer(null, null)); // &lt;- properly mocked
          new CloudFrontHandler(
              new OriginClient(event.Records[0].cf.request),
              new ResponseRenderer(callback, this.renderer),
          )
              .handle(); // &lt;- because CloudFrontHandler is not mocked, an error occurs here
      }
  }
  </code></pre>
  
  <p>For whatever reason <code>CloudFrontHandler</code> class does not get mocked (<code>OriginClient</code> and <code>ResponseRenderer</code> are properly auto-mocked). Following is my test class:</p>
  
  <pre class="lang-js prettyprint-override"><code>import "jest";
  import { Callback, CloudFrontRequest, CloudFrontRequestEvent } from "aws-lambda";
  import { mocked } from "ts-jest/utils";
  import { LambdaHandler, TemplateRenderer } from "../../../main/nodejs";
  
  import { CloudFrontHandler } from "../../../main/nodejs/edge/CloudFrontHandler";
  import { OriginClient } from "../../../main/nodejs/edge/OriginClient";
  import { ResponseRenderer } from "../../../main/nodejs/edge/ResponseRenderer";
  
  jest.mock("../../../main/nodejs/edge/CloudFrontHandler");
  jest.mock("../../../main/nodejs/edge/OriginClient");
  jest.mock("../../../main/nodejs/edge/ResponseRenderer");
  
  const MockedCloudFrontHandler = mocked(CloudFrontHandler);
  const MockedOriginClient = mocked(OriginClient);
  const MockedResponseRenderer = mocked(ResponseRenderer);
  
  describe("LambdaHandler", (): void =&gt; {
          it("should handle CloudFront request", (): void =&gt; {
                  const templateRenderer: TemplateRenderer = {} as TemplateRenderer;
                  const callback: Callback = jest.fn() as Callback;
                  const request: CloudFrontRequest = {} as CloudFrontRequest;
                  const event: CloudFrontRequestEvent = {
                      Records: [
                          {
                              cf: {
                                  request: request,
                              },
                          },
                      ],
                  } as CloudFrontRequestEvent;
  
                  let handler: LambdaHandler = new LambdaHandler(templateRenderer);
                  handler.handle(event, null, callback)
                  // todo
  
                  expect(MockedCloudFrontHandler).toHaveBeenCalledTimes(1);
                  expect(MockedOriginClient).toHaveBeenCalledTimes(1);
                  expect(MockedResponseRenderer).toHaveBeenCalledTimes(1);
          });
  });
  </code></pre>
  
  <p>(I keep source files and test files separately, thus all of these <code>src/main</code> <code>src/test</code> paths)</p>
  
  <p>Any reason why Jest wouldn't mock this one module class?</p>
  
  <p>-edit-</p>
  
  <p>The error message is:</p>
  
  <pre><code>TypeError: (intermediate value).handle is not a function
  </code></pre>