Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 基本Jest单元测试中出错-意外标识符| | u对象$defineProperty | babel运行时_Reactjs_Typescript_Jestjs_Babel Jest - Fatal编程技术网

Reactjs 基本Jest单元测试中出错-意外标识符| | u对象$defineProperty | babel运行时

Reactjs 基本Jest单元测试中出错-意外标识符| | u对象$defineProperty | babel运行时,reactjs,typescript,jestjs,babel-jest,Reactjs,Typescript,Jestjs,Babel Jest,我正在用酶和笑话编写一个简单的单元测试。 但是我对一个基本的初始测试有一个问题。 正如你在屏幕上看到的 失败的只是“渲染而不崩溃”测试 我尝试使用: “排除”:“/node_modules/”在tsconfig中 “testPathIgnorePatterns|transformIgnorePatterns”:“/node_modules/”在jest.config中 响应脚本测试--env=jsdom就像建议的那样 但它不起作用 请帮忙 mypackage.json { "name":

我正在用酶和笑话编写一个简单的单元测试。 但是我对一个基本的初始测试有一个问题。 正如你在屏幕上看到的

失败的只是“渲染而不崩溃”测试

我尝试使用:

  • 排除”:“/node_modules/”在tsconfig中
  • testPathIgnorePatterns|transformIgnorePatterns”:“/node_modules/”在jest.config中
  • 响应脚本测试--env=jsdom就像建议的那样
但它不起作用

请帮忙

mypackage.json

{
 "name": "my-app",
 "version": "0.12.0",
 "private": true,
 "dependencies": {
   "@types/jest": "23.3.13",
   "@types/lodash": "^4.14.120",
   "@types/node": "10.12.18",
   "@types/react": "16.7.20",
   "@types/react-dom": "16.0.11",
   "@types/react-helmet": "^5.0.8",
   "@types/react-redux": "^7.0.1",
   "@types/react-slick": "^0.23.3",
   "@types/styled-components": "^4.1.12",
   "axios": "^0.18.0",
   "babel-plugin-transform-runtime": "^6.23.0",
   "clipboard-polyfill": "^2.7.0",
   "core-js": "^2.6.5",
   "fscreen": "^1.0.2",
   "i18next": "^14.0.1",
   "moment": "^2.24.0",
   "normalizr": "^3.3.0",
   "polished": "^3.0.0",
   "react": "^16.7.0",
   "react-app-polyfill": "^0.2.2",
   "react-cookie": "^3.0.8",
   "react-dom": "^16.7.0",
   "react-dropzone": "^8.2.0",
   "react-helmet": "^5.2.0",
   "react-i18next": "^9.0.8",
   "react-media": "^1.9.2",
   "react-pose": "^4.0.8",
   "react-redux": "^6.0.0",
   "react-router-dom": "^4.3.1",
   "react-scripts": "^2.1.8",
   "react-slick": "^0.24.0",
   "redux": "^4.0.1",
   "redux-devtools-extension": "^2.13.7",
   "redux-thunk": "^2.3.0",
   "reselect": "^4.0.0",
   "styled-components": "^4.1.3",
   "tech-vnc": "<url-to->/tech-vnc.git",
   "tech-websocket-renderer": "<url-to->/tech-websocket-renderer.git",
   "testbirds-styleguide": "<url-to->/testbirds-styleguide.git",
   "typescript": "3.2.4",
   "url-search-params-polyfill": "^5.0.0"
 },
 "scripts": {
   "test": "react-scripts test --env=jsdom",
   "start": "react-scripts start",
   "prebuild": "npm run import-translations",
   "build": "react-scripts build",
   "build:nest": "env-cmd .env.nest npm run build",
   "import-translations": "node ./scripts/translations.js",
   "eject": "react-scripts eject"
 },
 "eslintConfig": {
   "extends": "react-app"
 },
 "browserslist": [
   ">0.2%",
   "not dead",
   "not ie <= 11",
   "not op_mini all"
 ],
 "devDependencies": {
   "@types/react-router-dom": "^4.3.1",
   "cross-fetch": "^3.0.0",
   "env-cmd": "^8.0.2",
   "enzyme": "^3.10.0",
   "enzyme-adapter-react-16": "^1.14.0",
   "fs-extra": "^7.0.1",
   "moxios": "^0.4.0"
  },
  "files": [
    "build"
   ]
 }
{
“名称”:“我的应用程序”,
“版本”:“0.12.0”,
“私人”:没错,
“依赖项”:{
“@types/jest”:“23.3.13”,
“@types/lodash”:“^4.14.120”,
“@types/node”:“10.12.18”,
“@types/react”:“16.7.20”,
“@types/react-dom”:“16.0.11”,
“@types/react头盔”:“^5.0.8”,
“@types/react redux”:“^7.0.1”,
“@types/react slick”:“^0.23.3”,
“@types/styled components”:“^4.1.12”,
“axios”:“^0.18.0”,
“巴别塔插件转换运行时”:“^6.23.0”,
“剪贴板多边形填充”:“^2.7.0”,
“核心js”:“^2.6.5”,
“fscreen”:“^1.0.2”,
“i18next”:“^14.0.1”,
“时刻”:“^2.24.0”,
“normalizer”:“^3.3.0”,
“抛光”:“^3.0.0”,
“反应”:“^16.7.0”,
“react应用程序polyfill”:“^0.2.2”,
“react cookie”:“^3.0.8”,
“react dom”:“^16.7.0”,
“react dropzone”:“^8.2.0”,
“反应头盔”:“^5.2.0”,
“react-i18next”:“^9.0.8”,
“反应媒体”:“^1.9.2”,
“反应姿势”:“^4.0.8”,
“react redux”:“^6.0.0”,
“反应路由器dom”:“^4.3.1”,
“反应脚本”:“^2.1.8”,
“反应平滑”:“^0.24.0”,
“redux”:“^4.0.1”,
“redux开发工具扩展”:“^2.13.7”,
“redux thunk”:“^2.3.0”,
“重新选择”:“^4.0.0”,
“样式化组件”:“^4.1.3”,
“tech vnc”:“/tech vnc.git”,
“tech websocket渲染器”:“/tech websocket渲染器.git”,
“testbirds styleguide”:“/testbirds styleguide.git”,
“类型脚本”:“3.2.4”,
url搜索参数polyfill“^5.0.0”
},
“脚本”:{
“测试”:“反应脚本测试--env=jsdom”,
“开始”:“反应脚本开始”,
“预构建”:“npm运行导入翻译”,
“构建”:“反应脚本构建”,
“构建:嵌套”:“env cmd.env.nest npm运行构建”,
“导入翻译”:“node./scripts/translations.js”,
“弹出”:“反应脚本弹出”
},
“eslintConfig”:{
“扩展”:“反应应用程序”
},
“浏览者”:[
">0.2%",
“没有死”,

“从Ezyme 3开始,您需要安装Ezyme以及与您使用的React版本相对应的适配器

还需要在您的中配置适配器:

如需更多帮助,请查看

并确保在exclude
tsconfig.json
中添加了
node\u模块

在我的案例中,我添加了以下内容:

    "exclude": [
        "node_modules",
        "build",
        "scripts",
        "acceptance-tests",
        "webpack",
        "jest"
    ],
例如检查


希望这能对您有所帮助。

从Ezyme 3开始,您需要安装Ezyme以及与您正在使用的React版本相对应的适配器

还需要在您的中配置适配器:

如需更多帮助,请查看

并确保在exclude
tsconfig.json
中添加了
node\u模块

在我的案例中,我添加了以下内容:

    "exclude": [
        "node_modules",
        "build",
        "scripts",
        "acceptance-tests",
        "webpack",
        "jest"
    ],
例如检查


希望这对您有所帮助。

您在代码中配置了适配器吗?您在代码中配置了适配器吗?我的setupTests.js文件中已经有了它:-(错误不是来自那个不幸的人你可以添加你的package.json文件吗?你添加了babel.config.js和jest.config.js吗?我添加了我的package.json和tsconfig.json。我不再有js.config文件了,因为我在有和没有js.config文件的情况下都会遇到错误。请尝试使用此配置?我的设置中已经有了它upTests.js文件:-(错误不是来自于那个不幸的错误。你可以添加你的package.json文件吗?你添加了babel.config.js和jest.config.js吗?我添加了我的package.json和tsconfig.json。我没有js.config文件了,因为我在有和没有它的情况下都会遇到错误。请尝试使用这个配置?