Great article! Note: I needed to assign "jest" to the "test" script in my package.json file in order for the npm run test script 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 spyOn and 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.
Hi, its worked!
could you explain a little bit about why is the .babelrc config needed?
Good question—I most likely added it based on some troubleshooting and advice I found online. It looks like Jest uses babel, but the configuration it has doesn't support a specific module structure.
It's almost a year ago, so maybe there are newer versions of tools available, and this configuration is not needed anymore. You can remove the plugin line from the .babelrc, and see if it breaks—if not, removing the plugin & the file should be fine too.
Elle K
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.