Created
May 7, 2021 10:10
-
-
Save nkhil/9adcf00c32d2b8d0781cae141c5131a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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