Jest encountered an unexpected token
Add this in your package.json jest config. Let me know if the issue still persists.
Add this in your package.json jest config. Let me know if the issue still persists.
Jest is installed, but is likely in your ./node_modules/.bin directory. You can append that to your command ./node_modules/.bin/jest –updateSnapshot. Since you already have jest as a scripts command in your package.json you can also run it with npm test — –updateSnapshot. npm automatically adds ./node_modules/.bin to your path. update: Newer versions of yarn will resolve node module bin scripts, so you can also just run yarn jest {cmd} and it … Read more
I solved this issue using: npm uninstall -g jest npm install -g jest npm cache clean npm install
Also using Babel, Typescript and Jest. Had the same failure, driving me crazy for hours. Ended up creating a new babel.config.js file specifically for the tests. Had a large .babelrc that wasn’t getting picked up by jest no matter what i did to it. Main app still uses the .babelrc as this overrides babel.config.js files. Install jest, ts-jest and babel-jest: babel.config.js (only used by … Read more
Edit: Several years have passed and this isn’t really the right way to do this any more (and probably never was, my bad). Mutating an imported module is nasty and can lead to side effects like tests that pass or fail depending on execution order. I’m leaving this answer in its original form for historical … Read more
From the command line, use the –testNamePattern or -t flag: This will only run tests that match the test name pattern you provide. It’s in the Jest documentation. Another way is to run tests in watch mode, jest –watch, and then press P to filter the tests by typing the test file name or T to run a single test name. If you have an it inside … Read more
There is the spyOn method, that was introduced with v19 some days ago, that does exactly what you are looking for