我在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 --详细的真时,我得到了
有关自定义转换的信息,您将在docs: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)发布于 2022-07-21 18:47:02
我发现了这个问题,我在文件夹的根目录中创建了.babelrc文件,并添加了
{
"env": {
"test": {
"presets": [
[
"@babel/preset-env"
]
]
}
}
}https://stackoverflow.com/questions/73071182
复制相似问题