Failed: npm test -t db-connection

please help, i’ve tried adding strings outside of the srv… other uri’s people have posted, deleting the node-modules and reinstalling etc

server@1.0.0 test
jest --passWithNoTests “db-connection”

Determining test suites to run…Setup Mongo Connection
FAIL test/db-connection.test.js
● Test suite failed to run

TypeError: Cannot read properties of undefined (reading 'close')

  17 | 
  18 |   async teardown() {
> 19 |     await this.global.mflixClient.close()
     |                                   ^
  20 |     await super.teardown()
  21 |   }
  22 | 

  at MongoEnvironment.teardown (test/config/mongoEnvironment.js:19:35)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.13s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection
(node:4694) Warning: Accessing non-existent property ‘count’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:4694) Warning: Accessing non-existent property ‘findOne’ of module exports inside circular dependency
(node:4694) Warning: Accessing non-existent property ‘remove’ of module exports inside circular dependency
(node:4694) Warning: Accessing non-existent property ‘updateOne’ of module exports inside circular dependency

MFLIX_DB_URI=mongodb+srv://m220student:m220password@mflix.nnlb0.mongodb.net/test
MFLIX_NS=sample_mflix
PORT=5000

Hi @Michael_Hayward, welcome to the community. :wave:
Have you followed the instructions mentioned in the Lecture: README: Setting Up mflix from Chapter 0?
Once you follow those steps, the file content from dotenv_win(or dotenv_unix in case of unix) will get copied to a new file called .env and eventually the application will pick those variables up from the environment.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

1 Like

Yes, i’ve done this and changed the file name to have .env

Hi @Michael_Hayward, can you remove /test from your connection string in the .env file and try again?

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

1 Like

5 posts were split to a new topic: Nodejs Database Connection Lab: Error: no test specified