Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
Jest Auto Mocking Issue - AWS SDK - Not properly auto mocking

I've ran into a strange issue when attempting to auto mock the AWS S3 client. I'm trying to write test cases to check if the S3 Class is instantiated with the correct parameters.

To write my test cases I'm auto mocking the S3 client which works for testing the upload function in S3. The problem I'm having is with the deleteObject function, every time I run my test around this function, Jest complains TypeError: s3Bucket.deleteObject is not a function

It seems like Jest isn't properly auto mocking the deleteObject function.

Wondering if anyone has any ideas here? I've tried various approaches and cannot figure out how to get around this...

Thank you!

Source file

import S3 from "aws-sdk/clients/s3";

function uploadToS3(bucketParams, cb) {
  const s3Bucket = new S3(bucketParams);
  s3Bucket.upload({ Key: "test", Body: "test" }, cb);
}

function deleteFromS3(bucketParams, cb) {
  const s3Bucket = new S3(bucketParams);
  s3Bucket.deleteObject({ Key: "test", Body: "test" }, cb);
}

module.exports = { uploadToS3, deleteFromS3 };

Test file:

jest.mock("aws-sdk/clients/s3");
import S3 from "aws-sdk/clients/s3";

const targetModule = require("source code");

// this passes as expected
it("should set s3 bucket parameters on upload", async () => {
  const bucketParams = { ... some params };

  targetModule.uploadToS3(bucketParams, (err: any) => {
    expect(S3).toBeCalledTimes(1);
    expect(S3).toBeCalledWith(bucketParams);
    expect(S3.prototype.upload).toBeCalledTimes(1);
  });
});

// this fails - TypeError: s3Bucket.deleteObject is not a function
it("should set s3 bucket parameters on delete", () => {
  const bucketParams = { ...some params };

  targetModule.deleteFromS3(bucketParams, (err: any) => {
    expect(S3).toBeCalledTimes(1);
    expect(S3).toBeCalledWith(bucketParams);
    expect(S3.prototype.deleteObject).toBeCalledTimes(1);
  });
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda