skip to Main Content

I’m trying to run tests with jest on a basic mongodb set-up with express. following the instructions in the jestjs.io documentation. When I run may package.json script: "test": "jest" I get the following error:

    TypeError: Class extends value undefined is not a constructor or null

      at Object.<anonymous> (node_modules/@shelf/jest-mongodb/environment.js:20:49)

The line in environment.js referenced above is:

module.exports = class MongoEnvironment extends TestEnvironment {

So the TestEnvironmentclass is undefined. Judging from other stack discussions it looks like there’s some circular reference issue. Possibly to be solved by changing the order of how the modules are run, but I don’t know how to do this?

I’ve tried changing my version of node, and I’ve also tried deleting my node_modules and reinstalling. When I run yarn check it tells me all my packages are in sync.

package.json:

...
  "dependencies": {
    "dotenv": "^16.0.1",
    "express": "^4.18.1",
    "mongodb": "^4.6.0"
  },
  "devDependencies": {
    "@babel/core": "^7.18.2",
    "@babel/preset-env": "^7.18.2",
    "@babel/preset-typescript": "^7.17.12",
    "@shelf/jest-mongodb": "^3.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "^27.5.1",
    "@types/mongodb": "^4.0.7",
    "@types/node": "^17.0.36",
    "jest": "^28.1.0",
    "jest-environment-node": "^27.0.0",
    "ts-jest": "^28.0.3",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.7.2"
  },
...

2

Answers


  1. Chosen as BEST ANSWER

    I got rid of this error by updating:

    "jest-environment-node": "^27.0.0",

    to

    "jest-environment-node": "^28.1.0",


  2. I was able to solve it from:

    const NodeEnvironment = require('jest-environment-node')
    

    to:

    const NodeEnvironment = require('jest-environment-node').default
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search