我有一个看起来像这样的函数:
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 })
}
我想测试功能连接。我已经像这样模拟了 DynamoDB 构造函数:
// See https://stackoverflow.com/questions/47606545/mock-a-dependencys-constructor-jest
jest.mock('aws-sdk', () => {
const DynamoDB = jest.fn().mockImplementation(() => {
return {};
});
return {
DynamoDB,
};
});
但是,这意味着DocumentClient
构造函数失败。我该如何嘲笑呢?