I try to mock s3 upload function with this instruction but when I use this pattern a have an
TypeError: s3.upload is not a function
// upload.test.js
const AWS = require('aws-sdk');
jest.mock('aws-sdk', () => {
const mS3 = { upload: jest.fn().mockReturnThis(), promise: jest.fn() };
return { S3: jest.fn(() => mS3) };
});
const s3 = new AWS.S3();
s3.upload({}).promise.mockResolvedValueOnce({ Bucket: 'XXX' });
I'm using also SQS and with this pattern I have another error:
AWS.SQS is not a constructor
How I can handle with it?
// upload.js
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
s3Params = {
Bucket: S3_BUCKET,
Key: `example.xml`,
ACL: 'public-read',
ContentType: 'application/json',
Body: Buffer.from(file)
}
}
await s3.upload(s3Params).promise();