gpt4 book ai didi

javascript - 在 vue 中使用 jest 时编译失败但测试用例通过

转载 作者:行者123 更新时间:2023-11-28 21:35:48 24 4
gpt4 key购买 nike

我将 jest 与 vue.js 一起使用并成功运行了我的测试,但我的模块构建失败了。我不明白为什么。这是我的代码。请帮助我。如果需要,我会提供更多。

包.json

{
"name": "weather-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test": "jest"
},
"dependencies": {
"@babel/core": "^7.7.2",
"@vue/test-utils": "^1.0.0-beta.29",
"babel-core": "^7.0.0-bridge.0",
"core-js": "^3.3.2",
"vue": "^2.6.10",
"vuex": "^3.1.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-plugin-eslint": "^4.0.0",
"@vue/cli-service": "^4.0.0",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"jest": "^24.9.0",
"vue-jest": "^3.0.5",
"vue-template-compiler": "^2.6.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {
"no-console": 0
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
],
"jest": {
"moduleFileExtensions": [
"js",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
}
}
}

我在屏幕上遇到的错误

Failed to compile.

./src/components/weather/weatherInfo.vue?vue&type=style&index=0&id=8f726072&lang=css&scoped=true& (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--6-oneOf-1-2!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/weather/weatherInfo.vue?vue&type=style&index=0&id=8f726072&lang=css&scoped=true&)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
JSONError: JSON Error in C:\Users\guest1\Projects\Vue Cli\wheather-app\package.json:
Unexpected token { in JSON at position 1057 while parsing near '... 2 versions" ], { "jest": { ...'
at module.exports (C:\Users\guest1\Projects\Vue Cli\wheather-app\node_modules\parse-json\index.js:26:19)
at Object.loadJson (C:\Users\guest1\Projects\Vue Cli\wheather-app\node_modules\cosmiconfig\dist\loaders.js:15:12)
at Explorer.loadPackageProp (C:\Users\guest1\Projects\Vue Cli\wheather-app\node_modules\cosmiconfig\dist\createExplorer.js:176:35)
at Explorer.loadFileContent (C:\Users\guest1\Projects\Vue Cli\wheather-app\node_modules\cosmiconfig\dist\createExplorer.js:230:12)
at Promise.resolve.then (C:\Users\guest1\Projects\Vue Cli\wheather-app\node_modules\cosmiconfig\dist\createExplorer.js:252:21)

我的测试用例结果

λ npm test

> weather-app@0.1.0 test C:\Users\guest1\Projects\Vue Cli\wheather-app
> jest

PASS src/test/App.test.js (6.524s)
App.test.js
√ equals loading to true] (47ms)

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 9.544s
Ran all test suites.

最佳答案

尝试更改 babel.config.js 中的预设

module.exports = {
presets: [
['@babel/preset-env']
]
}

关于javascript - 在 vue 中使用 jest 时编译失败但测试用例通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58930098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com