ddb_putitem.test.js - AWS Code Sample

ddb_putitem.test.js

const mockPutItem = jest.fn(); jest.mock("@aws-sdk/client-dynamodb/commands/PutItemCommand", () => ({ DynamoDB: function DynamoDB() { this.PutItemCommand = mockPutItem; }, })); const { params, run } = require("../../dynamodb/src/ddb_putitem"); //test function test("has to mock db#putItem", async (done) => { await run(); expect(mockPutItem).toHaveBeenCalled; done(); });