How to set up jest for es module
In this article, I will show a simple configuration to run jest tests for es module code.
Jest
Jest is a test framework developed by Facebook & often used in applications that use React. It's simple to set up & can be used to test any JS application....
how-to.dev2 min read
Great article! Note: I needed to assign "jest" to the "test" script in my package.json file in order for the
npm run testscript to work."scripts": { "test": "jest" },Out of the box, that comes as
"scripts": { "test": "echo \"Error: no test specified\" && exit 1" },Also, I can confirm that in Oct '22, I did not need to create the .bablerc config file. I found this article because I was trying to use
spyOnand getting the error:SyntaxError: The requested module jest/globals does not provide an export named spyOn. Installing the plugin to transform ES6 (modules) to CommonJS (@babel/plugin-transform-modules-commonjs) fixed this issue, exposing the spyOn function properly for use in my test files.