https://github.com/bboure/sls-test-eventbridge
https://github.com/bboure/sls-test-eventbridge
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bboure/sls-test-eventbridge
- Owner: bboure
- Created: 2021-10-13T20:50:10.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-16T19:34:36.000Z (almost 4 years ago)
- Last Synced: 2025-01-30T09:12:28.634Z (9 months ago)
- Language: TypeScript
- Size: 84 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Test Event-driven applications with Jest
This is a POC for a framework testing EventDriven applications with Jest.
It leverages AppSync subscriptions to subscribe to events and implement assertion helpers.Also see [this repo](https://github.com/bboure/appsync-eventbridge-subscriber)
for the AppSync part of this.# How it works
It leverages AppSync to subscribe to EventBridge Events.
First, create an EventBridge spy.
Then, execute the system under test.
Finally, assert on the spy;```ts
const spy = eventBridgeSpy({ url, apiKey });
await eventBridge
.putEvents({
Entries: [
{
Source: 'jest',
DetailType: 'somethingHappened',
Detail: JSON.stringify({ foo: 'bar' }),
},
],
})
.promise();await expect(spy).toReceiveEvent();
```As soon as the event is received, AppSync will resolve a promise and the assertion will take place.
If no event is received, the promise will time out (configurable) and the assertion will assume that no event is received.# Assertions
## `toReceiveEvent`
Tests that any event was received
## `toReceiveEventWithDetailType`
Tests taht an event with a given detail-type was received