Weird unit test failure messages

[j@work mflix-js]$ npm test -t mongoclient

server@1.0.0 test
jest --passWithNoTests “mongoclient”

Determining test suites to run…Setup Mongo Connection
FAIL test/lessons/mongoclient.spec.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:333:13)
  at async runJest (node_modules/@jest/core/build/runJest.js:404:19)
  at async _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
  at async runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

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

I appear to be getting the above error on every uni test.

Similar issue above.

My .env file is in the top level directory, which is mflix-js

Hi @Big_Cat_Public_Safety_Act,
Can you please confirm if you have done the following already?

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

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

@SourabhBagrecha

I have done that. The .env file is in the top level directory.

I tried this solution:

{
  "presets": [
    [
      "next/babel",
      {
        "preset-env": { "targets": { "node": true } }
      }
    ]
  ],
  "plugins": []
}

And it worked.

But now, I get:

[junlue@worktop3 mflix-js]$ node -v
v14.17.1
[junlue@worktop3 mflix-js]$ npm test -t db-connection

> server@1.0.0 test
> jest --passWithNoTests "db-connection"

Determining test suites to run...Setup Mongo Connection
Test environment found at "/home/junlue/Desktop/mflix-js/test/config/mongoEnvironment.js" does not export a "getVmContext" method, which is mandatory from Jest 27. This method is a replacement for "runScript".

Hi Junlue, can your please post the complete error message that you are getting after fixing the previous issue?

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

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.