0
export const produce = async (topic: string, url: string): Promise<void> => {
   await producer.connect();
   await producer.send({
      topic,
      compression: CompressionTypes.GZIP,
      messages: [{ key: `key-${Math.random() * 100000}`, value: url }],
   });

   await producer.disconnect();
};

我有一个像这样的发送消息 kafka 我该如何测试这个功能jest,因为如果我们想运行 jest,我们必须运行 serviceKafkazookeeper。我能做什么 ?

我曾尝试过类似的东西:

describe("Helper kafka", () => {
   describe("produce", () => {
      it("Pass 1 url should return 1", () => {
         expect(produce("testing", "URL")).toHaveBeenCalled();
      });
   });
});

它失败了,因为服务没有运行。

4

0 回答 0