gpt4 book ai didi

javascript - Jest/ react - TypeError : Cannot read property 'touchStart' of undefined

转载 作者:行者123 更新时间:2023-12-05 07:12:51 25 4
gpt4 key购买 nike

我已经使用 react、webpack 和 jest/enzyme 创建了项目来测试组件。在 webpack 中为文件添加了别名,并在“moduleNameMapper”内的 jest.config.js 中添加了相同的别名。但是在运行测试时出现以下错误:

测试套件运行失败

TypeError: Cannot read property 'touchStart' of undefined

2 | // import ReactSixteenAdapter from 'enzyme-adapter-react-16';
3 | // import Enzyme from 'enzyme';
> 4 | import Adapter from 'enzyme-adapter-react-16';
| ^
5 | import Enzyme, { shallow, configure } from 'enzyme';
6 | import WelcomeBody from '../components/welcome/WelcomeBody';
7 |

at Object.<anonymous> (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:64:36)
at Object.<anonymous> (node_modules/enzyme-adapter-react-16/src/index.js:2:18)
at Object.<anonymous> (app/src/__tests__/WelcomeBody.test.js:4:1)

有人可以帮忙解决这个问题吗。

最佳答案

如果您使用的是 TypeScript,请确保 tsconfig 文件中的“esModuleInterop”为真。这是一个示例:

"compilerOptions": {
"target": "es2019",
"moduleResolution": "node",
"module": "commonjs",
"lib": ["es2019"],
"sourceMap": true,
"outDir": "dist",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"resolveJsonModule": true,
"alwaysStrict": true,
"removeComments": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@src/*": ["./src/*"],
"@test/*": ["./test/*"]
},
"rootDirs": [
"./src",
"./test"
],
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},

关于javascript - Jest/ react - TypeError : Cannot read property 'touchStart' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60321647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com