This is my first foray into jest. I am attempting to run the "stock" test for my service, i.e., the one feathersjs sets up for you when it creates the service via the cli. The service uses an asychronous function with a callback, where I do some logging to the console as a final step. I am getting the error: "Cannot log after tests are done. Did you forget to wait for something async in your test?" I suspect that the test isn't waiting for the callback to complete before exiting, so when the callback executes tries to log after the tests finish.
Here's the stock test:
it('registered the service', () => {
const service = app.service('order');
expect(service).toBeTruthy();
});
I've tried some techniques mentioned in the documentation, like async/await:
it('registered the service', async () => {
const service = await app.service('order');
expect(service).toBeTruthy();
});
and I've tried using "done": I get the same error message each time.
Here's the part of the service code that's doing the logging:
amqp.connect(amqp_url, (err0, conn) => {
if(err0) {
throw(err0);
}
conn.createChannel((err1, ch) => {
if(err1) {
throw(err1);
}
ch.assertQueue(orchToOrderQName);
ch.consume(orchToOrderQName, function(msg) {
ch.ack(msg);
service.emit('create', msg);
});
orchToOrderChannel = ch;
});
conn.createChannel((err1, ch) => {
if(err1) {
throw(err1);
}
ch.assertQueue(orderToOrchQName);
orderToOrchChannel = ch;
console.log(" [*] Order is consuming messages from %s.", orchToOrderQName);
});
});
I think I need to find a way for the test to wait on the callback, but maybe the problem is elsewhere.