Description
I faced the same issue in my project and tried this one as a reference. Surprisingly, this reference project produced the same error. I use updated packages in my projects, but error is the same.
So, I cloned this repo, opened it in VS Code, then put in terminal:
npm install
npm run test
Here is the result:
Executing task: npm run test <
vue-test-utils-typescript-example@0.1.0 test d:\Projects\vue-test-utils-typescript-example
npm run test:unitvue-test-utils-typescript-example@0.1.0 test:unit d:\Projects\vue-test-utils-typescript-example
jestFAIL src/components/tests/HelloWorld.spec.ts
● Test suite failed to runJest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules". Here's what you can do: • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. • If you need a custom transformation specify a "transform" option in your config. • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option. You'll find more details and examples of these config options in the docs: https://jestjs.io/docs/en/configuration.html Details: D:\Projects\vue-test-utils-typescript-example\src\components\__tests__\HelloWorld.spec.ts:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import 'jest'; ^^^^^^ SyntaxError: Unexpected token import at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-cli/node_modules/jest-runtime/build/script_transformer.js:403:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.551s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-test-utils-typescript-example@0.1.0 test:unit:jest
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-test-utils-typescript-example@0.1.0 test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\LEVYAS.TRANSAS\AppData\Roaming\npm-cache_logs\2019-11-20T08_35_07_810Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-test-utils-typescript-example@0.1.0 test:npm run test:unit
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-test-utils-typescript-example@0.1.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
What could be the reason and how to fix it?
P.S. There is PR to this repo, I tried this one too and it doesn't produce that error. I tried to figure out the defining differences all the previous workday, but, unfortunately, with no success.