Getting “Error: Resolution method is overspecified”? in beforeEach and afterEach

79 Views Asked by At

When I use done in beforeEach or afterEach I get this error “Error: Resolution method is overspecified” and the test fails.

But now if remove the done() all my tests pass but the terminal hangs without exiting the test script.

I am using knex.js as a query builder.

Is there a solution to this problem?

beforeEach(async (done) => {
  await db.migrate.rollback(migrationConfig);
  await db.migrate.latest(migrationConfig);
  await db.seed.run(seedConfig);
  done();
});

// cleaning db before running tests
afterEach(async (done) => {
  await db.migrate.rollback(migrationConfig);
  done();
});

describe("POST /user/login", () => {
  it("should return a jwt after loging in user", (done) => {
    chai
      .request(server)
      .post("/user/login")
      .send({
        email: "[email protected]",
        password: "test123",
      })
      .end((err, res) => {
        res.should.have.status(200);
        res.should.be.json;
        res.body.should.have.property("token");
        done();
      });
  });
});

1

There are 1 best solutions below

0
Mikael Lepistö On

If you are using async handler functions, then you should not give it parameter done. Promise returned by async function will tell Mocha when executing the function is ready.

beforeEach(async () => {
  await db.migrate.rollback(migrationConfig);
  await db.migrate.latest(migrationConfig);
  await db.seed.run(seedConfig);
});

// cleaning db before running tests
afterEach(async () => {
  await db.migrate.rollback(migrationConfig);
});