[英]Jest(React) syntax error, configuration problem after the run of jest coomand
我在 package.json 文件中使用了這些包
"devDependencies": {
"@babel/core": "^7.18.9",
"@babel/plugin-transform-runtime": "^7.18.9",
"@babel/preset-env": "^7.18.9",
"@babel/preset-react": "^7.18.6",
"@types/jest": "^28.1.6",
"@vitejs/plugin-react": "^1.2.0",
"babel-jest": "^28.1.3",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"jest": "^28.1.3",
"jest-enzyme": "^7.1.2",
"jest-extended": "^3.0.1",
"jest-junit": "^14.0.0",
}
也有這樣的笑話配置
"jest": {
"testEnvironment": "jsdom",
"setupFilesAfterEnv": [
"<rootDir>/setupTests.js",
"./node_modules/jest-enzyme/lib/index.js",
"jest-extended"
],
"testResultsProcessor": "jest-junit"
}
Setup.tests.js 文件位於包含內容的根文件夾中
**
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
**
當我運行jest --runInBand --ci --verbose true我得到了
您將在文檔中找到這些配置選項的更多詳細信息和示例: https ://jestjs.io/docs/configuration 有關自定義轉換的信息,請參閱: https ://jestjs.io/docs/code-transformation
Details:
/setupTests.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { configure } from 'enzyme';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
我發現了問題,我在文件夾的根目錄中創建了 .babelrc 文件並添加
{
"env": {
"test": {
"presets": [
[
"@babel/preset-env"
]
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.