How to test a handler function which is wrapped in middy?

229 Views Asked by At

I want to test my handler which is wrapped in middleware using middy like this:

const main = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
  // .... //
};

export const handle = middy(main)
  .use(httpJsonBodyParser())
  .use(customMiddleWare(ID))
  .use(httpErrorHandler());

I want to ignore middy and all middleware and just want to test main by passing in mock events and expecting the result but I have no idea how to do it without exporting main.

1

There are 1 best solutions below

0
On

You can export const main = ... or have main in it's own file that's imported into the handler file.