Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created May 7, 2021 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhil/9adcf00c32d2b8d0781cae141c5131a8 to your computer and use it in GitHub Desktop.
Save nkhil/9adcf00c32d2b8d0781cae141c5131a8 to your computer and use it in GitHub Desktop.
const s3 = require('./s3') // This is the file where we use aws-sdk's S3 CopyObject method
const mockS3Instance = {
copyObject: jest.fn().mockReturnThis(),
promise: jest.fn().mockReturnThis(),
catch: jest.fn(),
}
jest.mock('aws-sdk', () => {
return { S3: jest.fn(() => mockS3Instance) }
})
describe('S3', () => {
it('calls aws-sdk copyObject method with correct parameters, async () => {
await s3() // This is the function that uses the copyObject method
expect(mockS3Instance.copyObject).toHaveBeenCalledWith({
Bucket: 'some-bucket',
CopySource: 'some-bucket/some/path/myfile.json,
Key: 'some-bucket/some/other/path/myfile.json',
})
expect(mockS3Instance.copyObject).toHaveBeenCalledTimes(1)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment