Class constructor NodeEnvironment cannot be invoked without 'new'

C:\Users\xxxxxxxxxxxxxxxxxxxxx\mflix-js>node -v
v16.15.0

C:\Users\xxxxxxxxxxxxxxxxxxxxxx\mflix-js>npm -v
8.5.5

npm test -t db-connection

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: Class constructor NodeEnvironment cannot be invoked without 'new'



  at new MongoEnvironment (test/config/mongoEnvironment.js:30:113)
  at async TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:317:13)
  at async runJest (node_modules/@jest/core/build/runJest.js:407:19)
  at async _run10000 (node_modules/@jest/core/build/cli/index.js:338:7)
  at async runCLI (node_modules/@jest/core/build/cli/index.js:190:3)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.196 s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection

Hi @Luiz_Avila,
A similar issue has been already addressed on the forum. Can you please take a look at this discussion?

Also, you can use the search feature at the top of the page to find more such related topics.

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

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

Hi @SourabhBagrecha I take a look in this discussion before and the solution didnt work for me.

The file .env is in the directory “mflix-js”.

SECRET_KEY=i change
MFLIX_DB_URI=mongodb+srv://m220student:m220password@mflix.ichange.mongodb.net/test
MFLIX_NS=sample_mflix
PORT=5000

and using “npm start”

(node:13264) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use node --trace-warnings ... to show where the warning was created)
listening on port 5000

and acessing localhost:5000

unable to pass the test: npm test -t db-connection
but i get the answer for the quiz Ticket: Connection

thanks for the reply @SourabhBagrecha