-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for middyfy function in lambda.ts, set esModuleInterop: true in tsconfig
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters