Writing jest test cases for a MongoDB server app.

I noticed, inside the testEnvironment file, it uses ‘require’ instead of ‘import’.
I changed it to ‘import’...🤔
Somehow it pops out syntaxErrors.🤦‍♂️

In my actual .test.js file, I use import all the time, never had any issue.

The Babel transform and babel-jest are also in the right place.

Anyone know why?

  • 1
    Jest is killing people with OCD...
  • 2
    I don't know much about jest but I'd guess this environment file is ran by the test-runner directly, before your tests, in node. It isn't transpiled nor used in a transpiled form.

    Node doesn't know import.
  • 1
    @nitwhiz the situation is kind bizarre. The same file allows class and async function 😵
  • 1
    @sunfishcc doesn't node support this by default?

    Can't try it right now but https://node.green/ told me so.
Add Comment