Consider this test, in which a message is sent from the test to topic 'out', and the tested code is expected to consume it and reply by sending a message to topic 'in'. In order to pass, I want to make sure a message was sent to topic 'in'.
it('...', async () => {
/* initialize kafkaConsumer and kafkaProducer here */
async function someCallback() {
// ...
}
await kafkaConsumer.subscribe({ topic: 'in', fromBeginning: true })
await kafkaConsumer.run({ eachMessage: someCallback })
await kafkaProducer.send({ topic: 'out', messages: [{ key: '1', value: '2' }] })
// How do I block here until someCallback is called?
})
I read about using done
but I can't have that while the test itself is defined async
, which I need in order to use await
. Is there a different way I'm not aware of?