WebStorm (2018.2.3) 中 Jest (23.5.0) 中未解析的函数或方法“xxx”

2024-01-19

我最近在 Jest (23.5.0) 和 WebStorm (2018.2.3) 智能感知方面遇到了问题。对于所有 Jest 方法(例如toHaveBeenCalledWith, toHaveLength),我收到一个Unresolved function or method "xxx" error.

I have @types/jest我参与了我所有的项目,除了最近的一个项目,当我被 CRA 开除后,这个项目就停止了。 奇怪的是,如果我删除所有项目node_modules,Jest 上的智能感知工作得很好 - 但一旦我跑了yarn install智能感知停止工作,我得到了Unresolved function or method "xxx"错误。所以我怀疑我的一个包裹导致了@types/jest停止工作。

问题截图:

我尝试过的:

  • 中讨论的所有方法JetBrains 论坛 https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000357324-Get-rid-of-Unresolved-function-method-variable-warning-in-Jest-test-files?page=1#community_comment_360000121219关于这个问题

  • This 替代解决方法 https://medium.com/front-end-hacking/fix-element-is-not-imported-jest-describe-it-expect-in-webstorm-aaf8c29ae3c2

  • 使Webstorm的缓存失效并重新启动

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

我的项目的设置:

  • 我的WebStorm版本是2018.2.3

  • My 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文件如下所示:

      {
          "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"
          }
      }
    

在网络风暴中: 偏好 |语言和框架 | JavaScript |库,按“下载...”,从可用存根列表中选择“jest”,按“下载并安装”

Source https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000357324-Get-rid-of-Unresolved-function-method-variable-warning-in-Jest-test-files

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WebStorm (2018.2.3) 中 Jest (23.5.0) 中未解析的函数或方法“xxx” 的相关文章

随机推荐