Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Problema de simulación automática de Jest - SDK de AWS: no se realiza correctamente la simulación automática

Me encontré con un problema extraño al intentar simular automáticamente el cliente de AWS S3. Estoy tratando de escribir casos de prueba para verificar si la clase S3 se instancia con los parámetros correctos.

Para escribir mis casos de prueba, estoy burlándome automáticamente del cliente S3 que funciona para probar la función de upload en S3. El problema que tengo es con la función deleteObject , cada vez que ejecuto mi prueba en torno a esta función, Jest se queja de TypeError: s3Bucket.deleteObject is not a function

Parece que Jest no se está burlando automáticamente de la función deleteObject .

¿Se pregunta si alguien tiene alguna idea aquí? He intentado varios enfoques y no puedo encontrar la manera de evitar esto ...

¡Gracias!

Archivo fuente

 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 };

Archivo de prueba:

 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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!