gpt4 book ai didi

Unresolved function or method "xxx" from Jest (23.5.0) in WebStorm (2018.2.3)(WebStorm(2018.2.3)中Jest(23.5.0)中未解析的函数或方法“xxx”)

转载 作者:bug小助手 更新时间:2023-10-25 14:54:39 27 4
gpt4 key购买 nike



I've been having an issue with Jest (23.5.0) and WebStorm (2018.2.3) intellisense lately. For all the Jest methods (e.g. toHaveBeenCalledWith, toHaveLength), I receive a Unresolved function or method "xxx" error.

最近,我一直对Jest(23.5.0)和WebStorm(2018.2.3)IntelliSense有意见。对于所有Jest方法(例如toHaveBeenCalledWith、toHaveLength),我收到一个未解析的函数或方法“xxx”错误。


I have @types/jest working in all of my projects except for my most recent one, which stopped working once I ejected from CRA.
Strangely enough, if I delete all my project's node_modules, the the intellisense on Jest works just fine - but as soon as I run yarn install the intellisense stops working and I get the Unresolved function or method "xxx" error. So I suspect one of my packages is causing @types/jest to stop working.

除了我最近的一个项目外,我的所有项目都有@Types/Jest在工作,这个项目在我退出CRA后就停止了工作。奇怪的是,如果我删除了项目的所有节点模块,Jest上的IntelliSense就能很好地工作--但只要我一运行Jest Install Install,IntelliSense就停止工作,并得到未解决的函数或方法“xxx”错误。因此,我怀疑我的某个包导致@type/jest停止工作。


Screenshots of the problem:

问题的屏幕截图:


Jest error message


@types/jest in project libraries


What I've tried:

我试过的是:



  • All the methods discussed in the JetBrains forum regarding this issue

    在JetBrains论坛上讨论的关于这个问题的所有方法



  • This alternate workaround

    此替代解决方法



  • Invalidating Webstorm's cache and restarting

    使WebStorm的缓存无效并重新启动



  • Reinstalling packages after deleting lock files

    删除锁定文件后重新安装包




My project's setup:

我的项目正在设置中:



  • My WebStorm version is 2018.2.3

    我的WebStorm版本是2018.2.3



  • My package.json looks as follows:

    我的Package.json如下所示:


      "dependencies": {
    "axios": "0.18.0",
    "classnames": "2.2.6",
    "dashjs": "2.9.0",
    "get-countries-info": "1.2.1",
    "lodash": "4.17.10",
    "moment": "2.22.2",
    "nuka-carousel": "4.3.5",
    "prop-types": "15.6.2",
    "querystringify": "2.0.0",
    "react": "16.4.2",
    "react-custom-scrollbars": "4.2.1",
    "react-dom": "16.4.2",
    "react-icons-kit": "1.1.7",
    "react-image-fallback": "8.0.0",
    "react-lottie": "1.2.3",
    "react-player-controls": "0.5.21",
    "react-redux": "5.0.7",
    "react-router-dom": "4.3.1",
    "react-select": "2.0.0",
    "react-toastify": "3.3.4",
    "redux": "4.0.0",
    "redux-promise": "0.6.0",
    "redux-thunk": "2.3.0",
    "uuid-validate": "0.0.3"
    },
    "devDependencies": {
    "autoprefixer": "9.1.5",
    "babel-core": "6.26.3",
    "babel-eslint": "9.0.0",
    "babel-jest": "23.4.2",
    "babel-loader": "7.1.2",
    "babel-preset-react-app": "3.1.2",
    "babel-runtime": "6.26.0",
    "case-sensitive-paths-webpack-plugin": "2.1.2",
    "chalk": "2.4.1",
    "css-loader": "1.0.0",
    "dotenv": "6.0.0",
    "dotenv-expand": "4.2.0",
    "enzyme": "3.6.0",
    "enzyme-adapter-react-16": "1.4.0",
    "enzyme-matchers": "6.0.4",
    "eslint": "5.5.0",
    "eslint-config-prettier": "3.0.1",
    "eslint-config-react-app": "2.1.0",
    "eslint-loader": "2.1.0",
    "eslint-plugin-flowtype": "2.50.0",
    "eslint-plugin-import": "2.14.0",
    "eslint-plugin-jest": "21.22.0",
    "eslint-plugin-jsx-a11y": "6.1.1",
    "eslint-plugin-prettier": "2.6.2",
    "eslint-plugin-react": "7.11.1",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "2.0.0",
    "fs-extra": "7.0.0",
    "generate-react-code": "1.3.0",
    "husky": "0.14.3",
    "html-webpack-plugin": "3.2.0",
    "jest": "23.5.0",
    "jest-enzyme": "6.0.4",
    "jest-mock-console": "0.4.0",
    "lint-staged": "7.2.2",
    "moxios": "0.4.0",
    "node-sass-chokidar": "1.3.3",
    "npm-run-all": "4.1.3",
    "object-assign": "4.1.1",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "3.0.0",
    "promise": "8.0.1",
    "prettier": "1.14.2",
    "raf": "3.4.0",
    "react-dev-utils": "5.0.2",
    "redux-devtools-extension": "2.13.5",
    "redux-logger": "3.0.6",
    "resolve": "1.8.1",
    "style-loader": "0.23.0",
    "sw-precache-webpack-plugin": "0.11.5",
    "url-loader": "1.1.1",
    "webpack": "3.12.0",
    "webpack-dev-server": "2.11.3",
    "webpack-manifest-plugin": "2.0.3",
    "whatwg-fetch": "2.0.4"
    },
    "lint-staged": {
    "*.js": [
    "prettier --write",
    "eslint --fix",
    "git add"
    ],
    "*.scss": [
    "prettier --write",
    "git add"
    ]
    },
    "babel": {
    "presets": [
    "react-app"
    ]
    }


  • My eslintrc.json file looks as follows:

    我的eslintrc.json文件如下所示:


      {
    "env": {
    "browser": true,
    "es6": true,
    "jest/globals": true,
    "jest": true,
    "node": true
    },
    "globals": {
    "process": true,
    "localStorage": true,
    "customScrollHandler": true,
    "customOnScrollEvent": true
    },
    "extends": [
    "react-app",
    "prettier",
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:jest/recommended",
    "plugin:jsx-a11y/recommended"
    ],
    "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
    "jsx": true
    }
    },
    "plugins": ["react", "jest", "prettier", "jsx-a11y"],
    "settings": {
    "react": {
    "version": "16.4.2"
    }
    },
    "rules": {
    "class-methods-use-this": "off",
    "semi": ["error", "always"],
    "no-console": ["error", { "allow": ["warn", "error"] }],
    "react/jsx-handler-names": "off",
    "import/no-namespace": "off",
    "import/namespace": "off",
    "import/prefer-default-export": "off",
    "import/default": "off",
    "react/prefer-stateless-function": "off",
    "react/jsx-curly-brace-presence": ["error", { "props": "never", "children": "ignore" }],
    "jsx-a11y/click-events-have-key-events": "off",
    "jsx-a11y/media-has-caption": "off",
    "jsx-a11y/no-static-element-interactions": "off",
    "jsx-a11y/label-has-for": "off",
    "jsx-a11y/no-noninteractive-element-interactions": "off",
    "jsx-a11y/href-no-hash": "off",
    "jsx-a11y/anchor-is-valid": "off"
    }
    }



更多回答

please provide a code snippet that shows up the issue

请提供显示该问题的代码片段

Sure! I've added some snapshots illustrating the problem.

好的!我已经添加了一些说明该问题的快照。

优秀答案推荐

In Webstorm :
Preferences | Languages & Frameworks | JavaScript | Libraries, press Download..., select 'jest' from the list of available stubs, press Download and Install

在WebStorm:首选项|语言和框架|JavaScript|库中,按下载...,从可用存根列表中选择‘jest’,然后按下载并安装


Source

来源



expect is resolved to window.expect in node_modules/react-custom-scrollbars/test.js, causing the issue. You can exclude this file from indexing by marking it as plain text (Mark as plain text in file right-click menu) - this should solve the issue

Expect被解析为node_MODULES/REACT-CUSTOM-SCROLLBAR/test.js中的window.expect,导致了该问题。您可以通过将此文件标记为纯文本(在文件右键单击菜单中标记为纯文本)将其从索引中排除-这应该可以解决问题



enter image description here



In my case (using "react": "^18.2.0", yarn 3.6.3 and Typescript) the issue was with missing import

在我的例子中(使用“REACT”:“^18.2.0”,纱线3.6.3和打字脚本)问题是缺少导入


import 'jest';

in setupTest.ts

在setupTest.ts中


After I added the line, web storm started seeing all Jest methods

在我添加了这行之后,Web Storm开始看到所有Jest方法


更多回答

the link isnt working

链路不起作用

Link updated, thx for feedback

链接已更新,谢谢反馈

Thanks so much!! I'm out of the office at the moment, but I'll check it as soon as I'm back - I'll keep you posted.

太感谢了!!我现在不在办公室,但我一回来就会检查的--我会随时与你保持联系的。

ctrl+click on expect to see what definition it's resolved to:)

按住Ctrl键并单击Expect以查看解析为什么定义:)

Genius! Thanks for the help.

天才!谢谢你的帮助。

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