"SyntaxError: Unexpected token u in JSON at position 0" while using jest-vue
See original GitHub issueHi @eddyerburgh , I’m trying to use jest-vue
with TypeScript support with Vue . My current setup of various files are as follows:
package.json
Jest Block
"jest": {
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
"moduleFileExtensions": ["ts", "tsx", "vue", "js", "json", "jsx"],
"verbose": true,
"mapCoverage": true,
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue"
}
}
Also I’m using ts-jest
, jest-vue
in conjunction with "vue-typescript-import-dts": "^3.1.1"
.
tsconfig.json
{
"compilerOptions": {
"jsx": "preserve",
"target": "es5",
"lib": ["dom", "es2015"],
"module": "es2015",
"moduleResolution": "node",
"outDir": "lib",
"isolatedModules": false,
"experimentalDecorators": true,
"declaration": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": true,
"removeComments": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"types": ["vue-typescript-import-dts"]
},
"include": ["./src/**/*"]
}
- Vue file components use
lang="ts"
andvue-class-component
withvue-property-decorator
packages
I’m getting the error as mentioned in Title, “SyntaxError: Unexpected token u in JSON at position 0” while using jest-vue
Not sure how to resolve this even after stumbling upon many links for solutions.
Full Stack Trace
> jest --coverage
FAIL __tests__/login.spec.ts
● Test suite failed to run
SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at compileTypescript (node_modules/jest-vue/lib/compilers/typescript-compiler.js:55:44)
at processScript (node_modules/jest-vue/lib/process.js:14:12)
at Object.module.exports [as process] (node_modules/jest-vue/lib/process.js:27:18)
console.info node_modules/vue/dist/vue.runtime.common.js:7751
You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html
Login Spec File
import Vue from 'vue'
import Login from '../src/components/login/Login'
describe('Hello Component', () => {
let $mounted
beforeEach(() => {
$mounted = new Vue(Login).$mount()
})
test('snapshot', () => {
let $html = $mounted.$el.outerHTML
expect($html).toMatchSnapshot()
})
})
Cannot share Login.vue file
Versions
"jest": "^21.2.1",
"jest-vue": "^0.8.1",
"ts-jest": "^21.1.3",
"ts-loader": "^3.0.5",
"typescript": "^2.5.3",
"vue-loader": "^13.3.0",
"vue-template-compiler": "^2.5.2",
"vue-typescript-import-dts": "^3.1.1",
"vue": "^2.5.0",
"vue-class-component": "^6.0.0",
"vue-property-decorator": "^6.0.0",
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How To Fix Unexpected token u in JSON at position 0 - Isotropic
From the causes, we can see that the fix for the Syntax Error "Unexpected token u in JSON at position 0" is relatively...
Read more >Unexpected token u in JSON at position 0 - Stack Overflow
Try this in the console: JSON.parse(undefined). Here is what you will get: Uncaught SyntaxError: Unexpected token u in JSON at position 0 at ......
Read more >Unexpected token u in JSON at position 0 - ItsJavaScript
The Unexpected token u in JSON at position 0 mainly occurs if we pass an undefined value to JSON.parse() method or $.parseJSON() method....
Read more >jest typescript syntaxerror: unexpected token 'export' - You.com
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >Unexpected token u in JSON at position 0 - YouTube
JavaScript : Uncaught SyntaxError : Unexpected token u in JSON at position 0 [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] ...
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
This is the top Google result for this issue, so I’ll add a quick note. This is not related to
jest-vue
. For me the error was due totsconfig.json
not being 100% JSON-correct. Removing a few dangling commas sorted the problem.Glad you solved the issue. an example repo would be great 🙂