我正在尝试使用JEST和graphql编写一些测试,但是无论我的.test.js文件中有什么(即使其中根本没有代码),也都会出现以下错误。
插件/预设文件仅允许导出对象 功能。在 /Users/oscarstein/Documents/Projekt/Biljettsystem/ticketgo/system/node_modules/babel-preset-stage-2/lib/index.js
我的.babelrc文件如下所示:
{
"presets": ["env", "stage-2"]
}
所以错误是由我使用预设的“ stage-2”引起的,当我删除它时,在测试中一切正常。但是,由于我的应用程序是使用Stage-2构建的,所以我想知道是否存在同时使用“ stage-2”和使JEST测试正常工作的解决方法?
package.json文件
{
"name": "system",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon --exec babel-node index.js",
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server": "^2.1.0",
"apollo-server-express": "^2.1.0",
"bcrypt": "^3.0.2",
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"dotenv": "^6.1.0",
"express": "^4.16.4",
"graphql": "^14.0.2",
"jest": "^24.0.0",
"jsonwebtoken": "^8.3.0",
"mysql2": "^1.6.4",
"nodemailer": "^4.6.8",
"nodemon": "^1.18.6",
"pg": "^7.6.0",
"sequelize": "^4.41.1",
"stripe": "^6.22.0"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1"
}
}
答案 0 :(得分:0)
Babel 7具有与以前版本不同的预设/插件依赖性。 LoudNoises发布的链接显示了如何更新依赖关系。对于您来说,npm i -D @babel/preset-env @babel/preset-stage-2
,然后更新您的.babelrc
:
{
"presets": ["@babel/env", "@babel/stage-2"]
}