cw_putmetricalarm.test.js - AWS Code Sample

cw_putmetricalarm.test.js

const mockPutMetricAlarm = jest.fn(); jest.mock("@aws-sdk/client-cloudwatch/commands/PutMetricAlarmCommand", () => ({ CloudWatch: function CloudWatch() { this.PutMetricAlarmCommand = mockPutMetricAlarm; }, })); const { params, run } = require("../../cloudwatch/src/cw_putmetricalarm"); //test function test("has to mock cloudwatch#putmetricalarm", async (done) => { await run(); expect(mockPutMetricAlarm).toHaveBeenCalled; done(); });