我正在尝试向我的应用添加测试,测试失败并出现以下错误:
测试套件无法运行
TypeError: environment.setup is not a function at node_modules/jest-runner/build/run_test.js:71:23
以下是我在项目中使用的配置文件:
.babelrc
{ "presets": [ "env", "react" ], "plugins": [ "transform-class-properties", "transform-object-rest-spread" ], "env": { "test": { "presets": [ "env", "react" ], "plugins": [ "transform-class-properties", "transform-object-rest-spread" ] } } }
jest.config.json
{ "transform": { "^.+\\.jsx?$": "babel-jest" }, "setupFiles": [ "raf/polyfill", "<rootDir>/src/tests/setupTests.js" ], "snapshotSerializers": [ "enzyme-to-json/serializer" ] }
的package.json
{ "scripts": { "build:prod": "webpack -p --env production", "build:dev": "webpack --env development", "dev-server": "webpack-dev-server", "test": "jest --config=jest.config.json" }, "author": "Lukasz 'Severiaan' Grela", "dependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-env": "^1.6.1", "babel-preset-react": "^6.24.1", "css-loader": "^0.28.9", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "enzyme-to-json": "^3.3.1", "extract-text-webpack-plugin": "3.0.2", "jest": "^22.3.0", "node-sass": "^4.7.2", "raf": "^3.4.0", "react": "^16.2.0", "react-dom": "^16.2.0", "react-redux": "^5.0.7", "react-responsive": "^4.0.3", "react-router-dom": "^4.2.2", "react-scripts": "1.0.17", "redux": "^3.7.2", "redux-logger": "^3.0.6", "redux-promise": "^0.5.3", "sass-loader": "^6.0.6", "style-loader": "^0.20.2", "webpack": "^3.11.0", "webpack-dev-server": "^2.11.1" }, "devDependencies": { "babel-jest": "^22.2.2" } }
可能是什么问题,是否有人遇到类似的问题?感谢任何提示:)
答案 0 :(得分:2)
添加
"jest": {
"testEnvironment": "node"
}
到你的package.json文件,它会是这样的:
.
.
.
"redux-promise": "^0.5.3",
"sass-loader": "^6.0.6",
"style-loader": "^0.20.2",
"webpack": "^3.11.0",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
},
"devDependencies": {
"babel-jest": "^22.2.2"
},
"jest": {
"testEnvironment": "node"
}
}