Mocking Secrets Manager module for JavaScript jest unit tests

Question:

I’m having trouble getting the AWS Secrets Manager module mocked for the jest unit tests… The part it errors on is the .promise(). When I remove that, the code doesn’t work for the real Secrets Manager so I think it needs to stay there. How do I mock the getSecretData function so that getSecretData.promise() will work for the mock?

Here is the SecretsManager.js code:

Here is the SecretsManager.test.js code:

This is the error I get when running the tests:

Any suggestions or pointers are greatly appreciated!
Thank you for looking at my post.

Answer:

I finally got it to work… figures it’d happen shortly after posting the question, but instead of deleting the post I’ll share how I changed the mock to make it work incase it helps anyone else.

Note: This is just the updated mock, the tests are the same as in the question above.

Leave a Reply