Jestjs Jest测试覆盖率-当文件不';我没有考试

Jestjs Jest测试覆盖率-当文件不';我没有考试,jestjs,Jestjs,我的React项目中有Jest测试,但还没有覆盖所有文件。但是,我遇到了以下错误: Failed to collect coverage from /home/user/Development/VideoManager/VideoManagerClient/src/components/AppContent/VideoListLayout/VideoListLayout.js ERROR: Cannot read property 'coverageData' of null STACK: T

我的React项目中有Jest测试,但还没有覆盖所有文件。但是,我遇到了以下错误:

Failed to collect coverage from  /home/user/Development/VideoManager/VideoManagerClient/src/components/AppContent/VideoListLayout/VideoListLayout.js
ERROR: Cannot read property 'coverageData' of null
STACK: TypeError: Cannot read property 'coverageData' of null
这里提到的文件还没有为其创建单元测试。我希望它只是被跟踪为缺乏覆盖率,从而使我的整个覆盖率统计下来,而不是抛出一个错误

此外,当我在IDE中运行单个测试时,我的日志中会出现更多的错误,因为它没有运行其他测试

我怎样才能解决这个问题

注:以下是我的Jest配置:

"jest": {
    "collectCoverage": true,
    "coverageReporters": [
      "html"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": 80
      }
    },
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/**/*.d.ts",
      "!src/serviceWorker.js"
    ],
    "resolver": "jest-pnp-resolver",
    "setupFiles": [
      "react-app-polyfill/jsdom"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/test/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
      "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}",
      "<rootDir>/test/**/*.{js,jsx,ts,tsx}"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>/test/setupTests.js",
      "<rootDir>/test/mock/.*",
      "<rootDir>/test/exclude/.*"
    ],
    "testEnvironment": "jsdom",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
      "^.+\\.module\\.(css|sass|scss)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
      "\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  }
“开玩笑”:{
“覆盖范围”:正确,
“搬运工”:[
“html”
],
“覆盖率阈值”:{
“全球”:{
“分支机构”:80,
“职能”:80,
“行”:80,
“声明”:80
}
},
“CollectionCoverage from”:[
“src/***.{js,jsx,ts,tsx}”,
“!src/***.d.ts”,
“!src/serviceWorker.js”
],
“解析器”:“jest pnp解析器”,
“设置文件”:[
“react应用程序polyfill/jsdom”
],
“SetupFileAfterEnv”:[
“/test/setupTests.js”
],
“测试匹配”:[
“/src/**/\\\\\\\\/**.{js,jsx,ts,tsx}”,
“/src/**/?(*)(规范测试)。{js,jsx,ts,tsx}”,
/test/***.{js,jsx,ts,tsx}
],
“testPathIgnorePatterns”:[
“/test/setupTests.js”,
“/test/mock/*”,
“/test/exclude/*”
],
“测试环境”:“jsdom”,
“testURL”:”http://localhost",
“转变”:{
“^.+\.(js | jsx | ts | tsx)$”:“/node_modules/babel jest”,
“^.+\.css$”:“/config/jest/cstransform.js”,
“^(?。*\(js | jsx | ts | tsx | css | json)$):”/config/jest/fileTransform.js”
},
“transformIgnorePatterns”:[
“[/\\\\\]节点单元模块[/\\\\].+\\.(js | jsx | ts | tsx)$”,
“^.+\.模块\(css | sass | scss)$”
],
“moduleNameMapper”:{
“^react native$”:“react native web”,
“^.+\\.module\\.(css | sass | scss)$”:“标识obj代理”,
“\\(css | sass | scss)$”:“标识obj代理”
},
“moduleFileExtensions”:[
“web.js”,
“js”,
“web.ts”,
“ts”,
“web.tsx”,
“tsx”,
“json”,
“web.jsx”,
“jsx”,
“节点”
]
}

我在使用
jest版本24.1.0
babel jest版本23.6.0
时遇到了完全相同的问题

通过将
babeljest
版本更新为
24.0.0
解决了这个问题


希望有帮助。

我在使用
jest 24.1.0版和
babel jest 23.6.0版时遇到了完全相同的问题

通过将
babeljest
版本更新为
24.0.0
解决了这个问题

希望能有帮助