Jest: Connection pool closed
Jan 4, 2023
Sometimes you want to wait until a method deep in the hierarchy has finished executing before completing the test. I was getting the following error:
MongoRuntimeError: The connection pool has been closed.
I’m working on a booking system that sends SMS notifications; the problem is that it’s an async method, and jest always finishes before the endpoint is complete.
To correct this error, I mocked my notification library:
…and I used this library to handle the waiting until my method completed its execution.
https://www.npmjs.com/package/wait-for-expect
Elegant and simple.