Unit Test and Integration Test for AWS Lambda/NodeJS in TypeScript | by Zijing Zhao | Level Up Coding

PHOTO EMBED

Mon Jan 31 2022 05:37:26 GMT+0000 (Coordinated Universal Time)

Saved by @jrsl

import { APIGatewayProxyEvent } from "aws-lambda";
import { lambdaHandler } from "../../src-ts/app";

describe('Unit test for app handler', function () {
    it('verifies successful response', async () => {
        const event: APIGatewayProxyEvent = {
            queryStringParameters: {
                a: "1"
            }
        } as any
        const result = await lambdaHandler(event)

        expect(result.statusCode).toEqual(200);
        expect(result.body).toEqual(`Queries: ${JSON.stringify(event.queryStringParameters)}`);
    });
});
content_copyCOPY

https://levelup.gitconnected.com/unit-test-and-integration-test-for-aws-lambda-nodejs-in-typescript-2235a0f69f5