Skip to content

Instantly share code, notes, and snippets.

@maatthc
Last active July 16, 2020 06:13
Show Gist options
  • Save maatthc/8cebb555bcddc54c7163e199d51a9b49 to your computer and use it in GitHub Desktop.
Save maatthc/8cebb555bcddc54c7163e199d51a9b49 to your computer and use it in GitHub Desktop.
(JavaScript) Jest test example use of toHaveBeenCalledTimes, objectContaining and arrayContaining in AWS Lambda
describe('Run method', () => {
const event: CloudWatchLogsEvent = {
awslogs: {
data: '',
},
}
it('should confirm shipments where emitted', async () => {
expect.assertions(2)
await service.run(event)
expect(sendBatchJSONMessages).toHaveBeenCalledTimes(1)
const expected = expect.objectContaining({
ExternalOrderId: expect.any(String),
OrderId: expect.any(String),
})
expect(sendBatchJSONMessages).toHaveBeenCalledWith(
'http://localhost:4576/',
expect.arrayContaining([expected]),
)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment