Jest unit testing solutions fail the initial test
See original GitHub issueVersion
3.0.0-beta.9
Steps to reproduce
Vue CLI v3.0.0-beta.9
? Please pick a preset: Manually select features
? Check the features needed for your project: Router, Vuex, Linter, Unit
? Pick a linter / formatter config: Airbnb
? Pick additional lint features: Lint on save, Lint and fix on commit
? Pick a unit testing solution: Jest
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
What is expected?
Test passed
What is actually happening?
Test failed
$ vue-cli-service test
FAIL tests/unit/HelloWorld.spec.js
● Test suite failed to run
SyntaxError: Unexpected token import
jest.config.js
module.exports = {
moduleFileExtensions: [
'js',
'jsx',
'json',
'vue',
],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest',
+ '^.+\\.js?$': 'babel-jest',
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
snapshotSerializers: [
'jest-serializer-vue',
],
testMatch: [
'<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))',
],
};
The .js
file should also be converted by babel-jest
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Jest — Fail Early (And Stop Testing If One Test Fails)
Jest comes with a built-in feature to fail early if one test fails. This tutorial shows you how to configure Jest to bail...
Read more >In Jest, how can I make a test fail? - Stack Overflow
Now imagine if someOperation() somehow passed, but you were expecting it to fail, then this test will still pass because it never went...
Read more >Jest Tutorial - JavaScript Unit Testing Using Jest Framework
a) First, write a failing test and see what output we get. Let's just change the result to some incorrect value in the...
Read more >Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why. Try using the debugging support built into...
Read more >Fail a test in Jest if an unexpected network request happens
Automatically failing unit tests with Jest in React when network requests are made will make your tests more reliable and easier to ...
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
Having the same issue. Initialized project as follows using the vue ui.
Development environment: Windows 10 Ent npm 6.1.0 vue 3.0.0-beta.16 node v8.11.1
Initially called the project “app” in the vue ui. Got the same error “unexpected token import” on the initial test without reconfiguring anything. When renaming the folder to “App” it worked.
When initializing the same project in a different folder it works without renaming it already. Therefore cannot recreate the problem in a different location right now and provide you with a repo.
@yyx990803 Oh yes, I did not notice before
?
Character 😅 But now this problem has arisen again, I don’t know how to reproduce it. After testing, I found out that as long as I change the directory name, it will affect the test results. 🤔I just changed
lyric
toLyric
and the test passed. When I changed it back to test it failed again.I seem to find the reasons, if I configured
babel-plugin-jsx-v-model
and the directory name islyric
, the test will not pass 🤔The above assumptions are not quite correct. I have re-initialized a project. When my
.babelrc
is configured as follows, the test fails:The test passes when my
.babelrc
is configured as follows:package.json
Once you combine them with 3 plug-ins, the test will fail! However, as long as the directory name is modified to be inconsistent with the
<app-name>
whenvue create <app-name>
is initialized, the test will pass! Oh! It drives me crazy!