title: Node Jest S3 upload mock
body: <p>I am trying to mock S3 upload functionality in the unit test case.  I am using jest and AWS-SDK-MOCK.</p>
  
  <p>Following is the code I have tried: </p>
  
  <pre><code>#functionality to mock
  
  const bucketUpload = async (
        bucketName: string,
        key: string,
        body: any
  ) =&gt; {
    const s3 = new S3();
    const params: S3.PutObjectRequest = {
      Body: body,
      Bucket: bucketName,
      Key: key
    };
    return await s3
    .upload(params)
    .promise()
    .then(result =&gt; result)
    .catch(err =&gt; err);
  };
  
  #Code used to mock it 
  
  import * as AWS from "aws-sdk";
  import * as AWSMock from "aws-sdk-mock";
  
  jest.mock("aws-sdk");
  
  describe("when using the create function", () =&gt; {
      const mockResponse = jest.fn((params: AWS.S3.PutObjectRequest, callback:any) =&gt;
      callback(null, {Location:"PublicLink"})
      );
      it("calls the put function", async () =&gt; {
         AWSMock.setSDKInstance(AWS);
         AWSMock.mock('S3', 'upload', mockResponse);
         ---- further test case ----
         expect(Mock).toHaveBeenCalledTimes(1);
   });
  });
  
  Error: Cannot read property 'upload' of undefined
  </code></pre>
  
  <p>This is the error I am facing while doing the job. When I tried to debug the issue I found everytime it mock the function made to upload data into the bucket</p>