How do I mock AWS S3 GetObjectCommand with jest using the v3 sdk?

Question:

Testing an s3 upload? The method to test is

This is my attempt at the test case.

The process gets to the parse method and throws an error “The bucket you are attempting to access must be addressed using the specific endpoint”

Answer:

For anyone who wants to mock the client directly, you can use the library aws-sdk-client-mock which is recommended by the AWS SDK team.

Some introductory tutorial

The initial steps:

And then you can mock it this way

You can also spy on the client

Leave a Reply