Last active
June 30, 2021 20:13
-
-
Save hoangsetup/c9080df5b83d746c307b1445bc303a71 to your computer and use it in GitHub Desktop.
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
import { mocked } from 'ts-jest/utils'; | |
import { Handler } from 'aws-lambda'; | |
import { middyfy } from '@libs/lambda'; | |
jest.mock('@libs/lambda'); | |
describe('hello', () => { | |
let main; | |
let mockedMiddyfy: jest.MockedFunction<typeof middyfy>; | |
beforeEach(async () => { | |
mockedMiddyfy = mocked(middyfy); | |
mockedMiddyfy.mockImplementation((handler: Handler) => { | |
return handler as never; | |
}); | |
main = (await import('./handler')).main; | |
}); | |
afterEach(() => { | |
jest.resetModules(); | |
}); | |
it('should return hello object', async () => { | |
const event = { | |
body: { | |
name: 'test-name' | |
} | |
} as any; | |
const actual = await main(event); | |
expect(actual).toEqual({ | |
message: `Hello ${event.body.name}, welcome to the exciting Serverless world!`, | |
event, | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment