Skip to content

Commit

Permalink
Tests: lambda.ts test (#46)
Browse files Browse the repository at this point in the history
 Test for middyfy function in lambda.ts, set esModuleInterop: true in tsconfig
  • Loading branch information
jasnoo authored Feb 22, 2024
1 parent 5d85ac9 commit 2cfee9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/libs/lambda.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import middy from '@middy/core';
import middyJsonBodyParser from '@middy/http-json-body-parser';
import { middyfy } from './lambda';

jest.mock('@middy/core', () => {
const use = jest.fn().mockImplementation(() => 'middyfied handler');
return jest.fn().mockImplementation(() => ({ use }));
});
jest.mock('@middy/http-json-body-parser');

const MOCK_MIDDY = middy as jest.MockedFunction<typeof middy>;

describe('middyfy', () => {
it('should wrap handler with middy, apply JSON body parser, and return middy instance', () => {
const handler = jest.fn();
const middyfiedHandler = middyfy(handler);
expect(middy).toHaveBeenCalledWith(handler);
const mockMiddyInstance = MOCK_MIDDY.mock.results[0].value;
expect(mockMiddyInstance.use).toHaveBeenCalledWith(middyJsonBodyParser());
expect(middyfiedHandler).toBe('middyfied handler');
});
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"removeComments": true,
"sourceMap": true,
"target": "ES2020",
"outDir": "lib"
"outDir": "lib",
"esModuleInterop": true,
},
"include": ["src/**/*.ts", "serverless.ts"],
"exclude": [
Expand Down

0 comments on commit 2cfee9d

Please sign in to comment.