ddb-table-create.test.js - AWS Code Sample

ddb-table-create.test.js

const mockCreateTable = jest.fn(); jest.mock("@aws-sdk/client-ddb/commands/CreateTableCommand", () => ({ DynamoDB: function DynamoDB() { this.CreateTableCommand = mockCreateTable; }, })); const { run } = require("../../lambda/tutorial/slotassets/ddb-table-create"); //test function test("has to mock ddb#createtable", async (done) => { await run(); expect(mockCreateTable).toHaveBeenCalled; done(); });