Reactjs 使用jest在我的react应用程序中集成测试失败

Reactjs 使用jest在我的react应用程序中集成测试失败,reactjs,jestjs,Reactjs,Jestjs,我正在尝试为酶+玩笑测试设置react应用程序,但在纱线测试中出现错误 我的package.json是 { "scripts": { "start": "webpack-dev-server --hot --open", "build": "webpack --config ./webpack.production.config.js --progress --profile --colors", "precommit": "lint-staged", "

我正在尝试为酶+玩笑测试设置react应用程序,但在纱线测试中出现错误

我的package.json是

{
  "scripts": {
    "start": "webpack-dev-server --hot --open",
    "build": "webpack --config ./webpack.production.config.js --progress --profile --colors",
    "precommit": "lint-staged",
    "format": "prettier --fix --write \"app/**/*.{js,jsx,json,css,scss}\"",
    "test": "jest"
  },
  "jest": {
    "moduleNameMapper": {
      "^config$": "<rootDir>/jest.config.js"
    }
  },
  "license": "MIT",
  "dependencies": {
    "@types/react": "^16.3.16",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-polyfill": "^6.26.0",
    "react": "^16.3.2",
    "react-slick": "^0.24.0",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.14.0",
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-jest": "^23.6.0",
    "babel-loader": "^7.1.4",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-polyfill": "^6.16.0",
    "husky": "^0.14.3",
    "jest": "^23.4.2",
    "jest-cli": "^23.6.0",
    "jest-enzyme": "^7.0.2",
    "webpack": "^4.6.0",
    "webpack-cli": "^2.1.2",
    "webpack-dev-server": "^3.1.1"
  }
}
我需要jest.config.js

module.exports = {
  moduleFileExtensions: ['js', 'jsx', 'json'],
  transform: {
    '^.+\\.(js|jsx)?$': 'babel-jest',
  },
  transformIgnorePatterns: ['<rootDir>/node_modules/'],
};
module.exports={
moduleFileExtensions:['js','jsx','json'],
转换:{
“^.+\\(js | jsx)?$”:“巴贝尔笑话”,
},
transformIgnorePatterns:['/node_modules/'],
};
你知道怎么解决这个问题吗?我找了很多,但什么也没找到

在setupTests.js中放置

window.matchMedia = window.matchMedia || function() {
return {
matches : false,
addListener : function() {},
removeListener: function() {}
};
};
停止所有任务,然后运行npm测试。现在应该可以工作了


我先尝试了一下,但同样的错误再次出现了
window.matchMedia = window.matchMedia || function() {
return {
matches : false,
addListener : function() {},
removeListener: function() {}
};
};