factory-girl icon indicating copy to clipboard operation
factory-girl copied to clipboard

When using factory with jest and mongoose, process doesn't end

Open charleswvs opened this issue 4 years ago • 1 comments

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

charleswvs avatar Apr 28 '20 15:04 charleswvs

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

7hibault avatar Jul 02 '20 08:07 7hibault