factory-girl
factory-girl copied to clipboard
When using factory with jest and mongoose, process doesn't end
I am having an issue using Factory girl with Jest.
When I create a factory, like this one:
const person = await factory.create('Person');
Inside a test, I get the following warn on Jest:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
And my process never ends, I am using the option jest --forceExit
as a way around, but it is not quite right to do that
In my experience, this is usually due to an unclosed db connexion, which means you're probably missing something like that
afterAll(async () => {
await connection.close();
await db.close();
});
https://jestjs.io/docs/en/mongodb