cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Node js Unit test with Jest

pavloN
Node Clone

I use the Jest framework to create unit tests. When I run them. there is the message at the end:

"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."

To exit, I use the command "--forceExit".
Also, I've tried to find an issue with --detectOpenHandles, but it didn't show anything.

I can't find what it hasn't closed, session or driver, or something else.
How could it be fixed?

const neo4j = require("neo4j-driver");
const driver = neo4j.v1.driver(
  `bolt://${host}`,
  neo4j.v1.auth.basic(username, password)
);

beforeAll(async () => {
  await cleanDB();
});

afterAll(async () => {
  await cleanDB();
  driver.close();
});

async function cleanDB() {
  await runQuery(`...query`);
}

async function runQuery(query) {
  const session = driver.session();
  return session
    .writeTransaction(tx => tx.run(query))
    .then(result => {
      session.close();
      return result;
    })
    .catch(error => {
      session.close();
      return { error };
    });
}

describe(`bla-bla-bla`, function() {
  beforeAll(async () => {
    await dataBaseLoader(data);
  });

  test(`bla-bla-bla`, async function() {
    const result = await runQuery(
    '...query' );
   //Body of Test
    expect(result).toStrictEqual(expected);
  });
0 REPLIES 0