Basic example:
await serverlessSpyListener.waitForSqsMyQueue();
You can use conditions to wait for a particular event. You can also use generic (TestData
) to strongly type the event.
await serverlessSpyListener.waitForSqsMyQueue<TestData>({
condition: (d) => d.body.id === id,
});
Interception of SQS events intercepts events when Lambda consumes them. spySqsWithNoSubscriptionAndDropAllMessages
when creating ServerlessSpy in CDK. With this flag on, an additional Lambda will be created that will consume messages and throw them away (= lost forever ⛔). Of course, that is undesirable in most cases, but it could be useful for some tests.
Check this{:target="_blank"} and this{:target="_blank"} test.