Failing to run Jest tests with Vue CLI 3 project
See original GitHub issueEnvironment
node -v
: v9.4.0npm -v
: 6.3.0npm ls jest
ornpm ls react-scripts
(if you haven’t ejected):
foo@0.1.0 C:\Foo\Source
`-- @vue/cli-plugin-unit-jest@3.0.0
`-- jest@23.5.0
-
your vscode-jest settings if customized:
- jest.pathToJest? N/A
- jest.pathToConfig? N/A
- anything else that you think might be relevant? N/A
-
Operating system: Windows 10
Prerequisite
- are you able to run jest test from command line? Yes
- how do yo run your tests from command line? (for example:
npm run test
ornode_modules/.bin/jest
)vue-cli-service test:unit
ornpx jest
Steps to Reproduce
The VS Code Output window shows lots of errors that look like this:
FAIL src/framework/Guid.Test.ts
? Test suite failed to run
Jest 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:
C:\Bitbucket\Bridge.Staffing\Source\Client\src\framework\Guid.Test.ts:3
import "core-js/modules/es6.regexp.constructor";
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
As indicated in the comment here, I tried setting jest.pathToJest
to:
cross-env BABEL_ENV=test vue-cli-service test:unit
However, this doesn’t work, the unexpected token import
error continues.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
vue.js - Vue3/TS/Jest/testing-ligrary: can not run tests
I create project through vue cli with options: vue3, TS, JEST and add @testing-library/vue . my package.json looks like this
Read more >Cannot run Jest unit tests with @vue/cli-service : WEB-34734
The test as scaffolded by Vue CLI, works. You know this by running npm run test:unit - you'll see the test passes just...
Read more >vue/cli-plugin-unit-jest
Note that directly running jest will fail because the Babel preset requires hints to make your code work in Node.js, so you must...
Read more >Setting up for TDD - Vue Testing Handbook
Create a new project by running vue create [project-name] . Choose "Manually select features" and "Unit Testing", and "Jest" for the test runner ......
Read more >Vue.js 3 Unit Testing Setup & Basics Tutorial
Lesson Project · Jest is the framework used to perform unit testing. · Vue CLI Unit Jest Plugin installs and configures the necessary...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for that link. Adding this code at the top of
jest.config.js
fixes the problem:This actually works. But why does vscode jest extension need these variables and launching jest by command not?