Node.js 使用amqplib MOCK库进行rabbitMQ单元测试

Node.js 使用amqplib MOCK库进行rabbitMQ单元测试,node.js,unit-testing,rabbitmq,node-amqplib,Node.js,Unit Testing,Rabbitmq,Node Amqplib,我正在尝试使用编写单元测试,但无法使用来自消费者的消息,我正在变得未定义,并且尝试调试,但未成功 describe("Rabbitmq testing Server", () => { let connection, channel; before(async () => { connection = await amqplib.connect("amqp://localhost"); channel = await connecti

我正在尝试使用编写单元测试,但无法使用来自消费者的消息,我正在变得未定义,并且尝试调试,但未成功

describe("Rabbitmq testing Server", () => {
    let connection, channel;

    before(async () => {
        connection = await amqplib.connect("amqp://localhost");
        channel = await connection.createChannel();

        await channel.assertExchange(messagesExchange, exchangeType);

        isCreated = await channel.assertQueue(queue);
        isCreated.queue ? console.log('queue created') : 'Queue not created or already exist';

        await channel.bindQueue(queue, messagesExchange, routingKey);

        const isPublish = channel.publish(messagesExchange, routingKey, Buffer.from('should pass test')).valueOf();
        isPublish ? console.log('message published successfully') : 'message not published';
    });

    it("should create the channel", () => {
        assert.isObject(channel);
    });

    it("should register the method call", () => {
        expect(connection.createChannel()).to.have.been.all.keys;
        expect(connection.createChannel()).to.have.been.all.members;
    });

    it("should consumer consume message from queue", async () => {
        let result: string;
        const consumer = await channel.consume(queue, (msg) => {
            result = msg.content.toString();
            console.log(result);
        }, { noAck: true });

        // expect(result).to.be.equal(JSON.stringify({ success: true }));
    });

    after(() => {
        amqplib.reset();
    })
前两个测试通过,但第三个测试得到未定义的值。任何帮助都将不胜感激