simonexmachina / factory-girl

A factory library for node.js and the browser inspired by factory_girl
MIT License
552 stars 86 forks source link

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

Open charleswvs opened 4 years ago

charleswvs commented 4 years ago

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

7hibault commented 4 years ago

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