api-design-node-v3 icon indicating copy to clipboard operation
api-design-node-v3 copied to clipboard

Unable to run tests

Open c1oneman opened this issue 2 years ago • 2 comments

[email protected] test-routes npm run test -t router

[email protected] test cross-env NODE_ENV=testing jest --forceExit --detectOpenHandles --silent "router"

RUNS src/resources/item/tests/item.router.spec.js node:internal/process/promises:246 triggerUncaughtException(err, true /* fromPromise */); ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: Cannot read properties of undefined (reading 'dropDatabase')".] { code: 'ERR_UNHANDLED_REJECTION' }

c1oneman avatar Oct 27 '21 15:10 c1oneman

I was able to get past this by editing test-db-setup.js and changing the afterEach() function to include a try/catch:

afterEach(async done => {
  try {
    await mongoose.connection.db.dropDatabase()
    await mongoose.disconnect()
  } catch (err) {
    console.log(err)
  }
  await mongoose.disconnect()
  return done()
})
afterAll(done => {
  return done()
})

toddtyler avatar Nov 19 '21 01:11 toddtyler

On windows, I edited the test-db-setup.js file and also the dev.js and testing.js files contained in the config folder.

I changed all the instances of mongodb://localhost:27017 to mongodb://0.0.0.0:27017 I got this from a (stackoverflow)[https://stackoverflow.com/questions/46523321/mongoerror-connect-econnrefused-127-0-0-127017] answer, specifically the second answer.

jhhornn avatar Sep 26 '22 08:09 jhhornn