gpt4 book ai didi

react-native - IDE 不识别 Jest 及其函数

转载 作者:行者123 更新时间:2023-12-05 04:48:49 28 4
gpt4 key购买 nike

我有一个基本的 react-native/expo 模板应用程序。我在开发依赖项中添加了 jest-exporeact-test-renderer,并且还像 expo docs for testing 中记录的那样更新了 package.json .

{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
...
"test": "jest"
},
"dependencies": {
"expo": "~41.0.1",
...
"react": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@testing-library/jest-native": "^4.0.1",
"@testing-library/react-native": "^7.2.0",
"jest-expo": "^41.0.0",
"react-test-renderer": "^17.0.2"
},
"private": true,
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)"
],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
]
}
}

我还添加了 React Native Testing Library 来测试 UI。测试运行良好。

但问题是 WebStorm IDE 无法识别 Jest 及其功能。

enter image description here

enter image description here

你能帮我解决这个问题吗?

更新

根据评论,我尝试通过设置配置安装 Typescript Jest 类型定义,还尝试使用 yarn/npm 安装。但这没有帮助。

enter image description here

另一个更新

但是,如果我取消选中项目的 node_modules 库,则会选择 Jest 类型定义。

enter image description here

但是这样做,其他类型的node_modules就不行了!

最佳答案

在首选项 - 语言和框架 - JavaScript - 库中,按下载,然后从列表中选择 jest,按下载并安装。如果它不起作用,请在本地文件夹中尝试 npm i @types/jest

关于react-native - IDE 不识别 Jest 及其函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67889135/

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