Skip to content
Advertisement

Unable to run JEST test

I’m facing an issue when I try to import something using require() function in jest test file.

script2.test.js

JavaScript

Package.json

JavaScript

babel.config.cjs

JavaScript

I’m getting following errors when I run the test using npm test

JavaScript

I’m new to JEST, any help is much appreciated. My Node version is 14.17.3 Thanks you.

Advertisement

Answer

It seems that one still needs to jump through the hoops to make jest work with ESM.

In package.json change your script to:

JavaScript

And in script2.test.js use import:

JavaScript

P.S. This was tested with node 14.15.1

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement