Я хочу протестировать функцию, которая подключается к службе RabbitMQ, передавая неверный хост:
connect(host) {
return new Promise((resolve, reject) => {
amqp.connect(host)
.then((conn) => {
resolve(conn);
})
.catch((err) => {
throw new Error(err);
});
});
}
И здесь я тестирую это
it('should fail connect to RabbitMQ service passing wrong host to instance.', async () =>
const err = await rabbitmqmailer.connect('amqp://localhot')
assert.throws(Error, err);
});
Но я получил ошибкуна моем терминале, но мой модульный тест не подтверждает это.
Unhandled rejection Error: Error: getaddrinfo EAI_AGAIN localhot localhot:5672
at _amqplib2.default.connect.then.catch.err (/home/ubuntu/Desktop/easy-tracking/backend/src/components/rabbitmqmailer/rabbitmqmailer.dal.js:3:7)
at tryCatcher (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/promise.js:690:18)
at _drainQueueStep (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/home/ubuntu/Desktop/easy-tracking/backend/node_modules/amqplib/node_modules/bluebird/js/release/async.js:17:14)
at processImmediate (timers.js:632:19)
1) should fail connect to RabbitMQ service passing wrong host to instance.
7 passing (2s)
1 failing
1) RabbitMQMailer component.
RabbitMQMailer configuration information.
should fail connect to RabbitMQ service passing wrong host to instance.:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/ubuntu/Desktop/easy-tracking/backend/src/components/rabbitmqmailer/rabbitmqmailer.test.js)
Что я делаю не так?