Close amqp connection on jest exit

Viewed 128

I have jest test which look similar to this

const conn = amqplib.connect('amqp_url', {
    timeout: 10 * 1000,
});
describe(`Testing.. `, (case) => {
    test(`Test n`, (done) => {
        conn
            .then(function(conn) {
                return conn.createChannel();
            })
            .then(function(ch) {
                ch.assertQueue('')
                    .then(function(q) {
                        ch.bindQueue(q.queue, case.exchange, case.bKey)
                            .then(() => {
                                ch.consume(q.queue, function(msg) {
                                   //veryfing logic goes here
                                   done();
                                });
                                ch.publish(case.exchange, case.rKey, Buffer.from(case.orgMsg));
                            })
                    });
            })
    });
});


It works but the connection is obviously not closed after the test.

Can someone please explain how should I close connection to amqp after all test are passed?

0 Answers
Related