我意识到这个问题已经被问了好几次了,但我遇到的所有解决方案似乎对我都不起作用。在尝试为Vue应用程序运行Jest测试时,我遇到了以下错误。 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 yo
我正在一个应用程序中工作,并试图添加一个测试框架,以实现整个应用程序的自动化测试。我使用的是Vue,电子,TypeScript和Node,并且很难获得任何实际使用组件来运行的测试。出于某种原因Jest似乎不想使用节点模块..。我很少幸运地在网上找到任何能解决这个问题的方法。
任何对该主题有任何了解的人,如果在运行测试时对如何解决导入这些节点模块的问题有任何指点或想法,我们将不胜感激。我无法想象,这是不可能做到的,但我真的没有什么可以通过我的搜索找到。
错误:
$ npm run test
> mdc@1.0.0 test C:\Users\daniel\Desktop\MDC\mdc
我从babel 6迁移到babel 7,我发现了一些我无法纠正的错误。
未知:意料之外的标记(即使我使用@babel/plugin-建议-对象-rest-扩展)。
这个问题出现在我运行jest单元测试套件的时候。
错误日志:
► yarn run test:unit
yarn run v1.13.0
$ jest --clearCache && jest --coverage=false
Cleared /tmp/jest_rs
FAIL test/unit/store.test.js
● Test suite failed to run
unknown:
当我运行jest时,我会得到以下错误。看起来原因是与类型记录相关的,但是我在package.json中有一些类型记录处理,所以我不知道为什么它不会被处理。
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.
...
Details:
/Users/ryancocuzzo/ex/test/example/mobile-a
自从我尝试开始使用Jest以来,我一直对Jest有困难。没有我试图运行的测试和尝试通过Jest的选项,我永远不会在控制台中得到' pass‘/ 'Fail’输出结果。
开玩笑总是输出“完成”
使用“Nuxt”有一个默认测试,编写如下:
import { mount } from '@vue/test-utils'
import Logo from '@/components/Logo.vue'
describe('Logo', () => {
test('is a Vue instance', () =
是一个有用的方法,在构建和执行所有东西时都工作得很好。但是,所有Jest-Jest都会失败,并显示以下错误:
TypeError: replaceAll is not a function
以下是我的依赖项:
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-i18n": "^8.22.0",
我使用Jest制作的代码库,但我找不到一种方法来运行导入组件的简单Vue3测试。这在使用Vue-cli创建的应用程序中工作得很好,但我找不到一种方法来让Jest在使用Vue3的Vue-Vite应用程序中工作。下面是我遇到的错误 FAIL docs/homepage.spec.js
● Test suite failed to run
Vue packages version mismatch:
- vue@3.0.0 (/var/www/html/my_project_vue3_vite/node_modules/vue/index.js)
- vue
我试图通过jest将单元测试添加到现有的vue项目中,但是当我尝试运行第一个测试时,我得到了一个错误:
Vue软件包版本不匹配:
- vue@2.5.16
- vue-template-compiler@2.6.6
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loa
我一直在尝试配置我的jest.config.js文件,以便在我用TypeScript编写的Vuejs应用程序上运行一些测试。Jest在解析node_modules中的json文件时不断给出一个错误,说它遇到了一个意外的令牌。不确定问题是什么,因为当我尝试导入vue文件时,它工作得很好。下面是jest抛出的错误 Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot
在升级到Vue 3之后,在GitHub操作中运行单元测试时,会得到以下错误:
> vue-cli-service test:unit
● Validation Error:
An unknown error occurred in @vue/cli-plugin-unit-jest:
Cannot resolve "@vue/vue3-jest" module. Please make sure you have installed "@vue/vue3-jest" as a dev dependency.
GitHub操作脚本使用npm c
我使用Vue与webpack模板,我试图运行测试与Jest。我还使用Pug来呈现模板。
但是当我运行测试时,我得到了一个错误:
[vue-jest] Error: Error: the "filename" option is required to use includes and extends with "relative" paths
at undefined line 2
at error (node_modules/vue-jest/lib/throw-error.js:2:9)
at module.exports (node_m
目前,Jest未能通过测试,因为它找不到组件中调用的模块:
FAIL tests/Unit/VHeaderBar.spec.ts
● Test suite failed to run
Cannot find module '@@/public/assets/images/placeholder.png' from 'VHeaderBar.vue'
at Resolver.resolveModule (node_modules/jest-runtime/node_modules/jest-resolve/build/index.
我正在尝试在项目中安装vue-test-utils和jest。这是一个vue-cli项目,但我在最初运行它时并没有设置测试。 它会找到测试,但在import语句上失败。 这就是错误。 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 w
我使用的是配置了Jest和Typescript的NuxtJS。现在,由于一个异常,我的小示例测试将无法运行。 Details:
/home/xetra11/development/myapp/test/Navigation.spec.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { mount } from '@vue/test-utils';
我在Jest中得到了下面的错误,但不清楚为什么即使在添加testEnvironmentOptions之后
TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')
at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:72:28)
at async TestScheduler.scheduleTests (node
我正试着向大家介绍我目前的项目。
但是,在最初的设置过程中,我遇到了这个错误,并且它没有正常运行。
我怎么才能解决这个问题?
我目前正在使用来自vue-cli的vue2。
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'html')
at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:72:44)
at async TestS
我正在尝试使用Jest在Vue中建立单元测试。但是,我得到了这个错误:
● Test suite failed to run
...
SyntaxError: Cannot use import statement outside a module
>1 | import editUser from '@/components/forms/editUser.vue';
| ^
2 | import TestComponent from '@/pages/user/UserMyProfile.vue';
3 | import { shal