I have a function that looks like this:
function connect() {
const secret = 'secret';
const key = 'key';
const region = 'region';
const client = new AWS.DynamoDB({
secret,
key,
region
});'
return new AWS.DynamoDB.DocumentClient({ service: client })
}
I would like to test the function connect. I have mocked the DynamoDB constructor like this:
// See https://stackoverflow.com/questions/47606545/mock-a-dependencys-constructor-jest
jest.mock('aws-sdk', () => {
const DynamoDB = jest.fn().mockImplementation(() => {
return {};
});
return {
DynamoDB,
};
});
However, this means that the DocumentClient
constructor fails. How do I mock that as well?