Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 未定义Jest/ESLint失败_React Native_Jestjs_Eslint_Babel Jest - Fatal编程技术网

React native 未定义Jest/ESLint失败

React native 未定义Jest/ESLint失败,react-native,jestjs,eslint,babel-jest,React Native,Jestjs,Eslint,Babel Jest,我刚刚用npx react native init生成了一个新项目,ESLint在我的一个测试文件中抱怨: 9:1 error 'describe' is not defined no-undef 12:5 error 'beforeEach' is not defined no-undef 16:5 error 'afterEach' is not defined no-undef 20:5 error 'test' is not defi

我刚刚用
npx react native init
生成了一个新项目,ESLint在我的一个测试文件中抱怨:

   9:1   error  'describe' is not defined    no-undef
  12:5   error  'beforeEach' is not defined  no-undef
  16:5   error  'afterEach' is not defined   no-undef
  20:5   error  'test' is not defined        no-undef
  28:17  error  'fail' is not defined        no-undef
  30:13  error  'expect' is not defined      no-undef
基于此,我添加了:

env: {
    jest: true,
},
到我的
.eslintrc.js
文件。然而,ESLint仍在抱怨:

  28:17  error  'fail' is not defined  no-undef
有没有人已经经历并解决了这个问题

以下是
package.json
中的jest依赖项版本:

"babel-jest": "^26.5.2",
"jest": "^26.5.3",

好的,原来Jest使用了Jasmine的
fail()

通过添加茉莉花更新了
.eslintrc.js
,效果良好。没有更多的错误

env: {
    jasmine: true,
    jest: true,
},

如果您在编辑器中看到此消息,请确保将其关闭并再次打开。有时编辑器无法检测到ESLint配置是否已更改。不幸的是,我从手动执行命令的终端上看到了它。除此之外,我不太确定。我昨天遇到了与您完全相同的问题,我通过在配置中添加
env
属性解决了这个问题。我使用了,所以它只对测试文件启用(我必须调整过滤器,并匹配我的命名方案
*.test.ts
),但它确实起了作用-ESLint停止抱怨。我还在覆盖中添加了一个小的
“rules”
部分,以调整测试的一些风格规则。您是否也在您的一个测试中使用
fail
?好的,所以我添加了一个非常简单的测试it(“fails”,function(){fail(“always”);}`并且测试失败(预期)。ESLint还抱怨
no undef
,但它对
descripe
或“expect”之类的内容没有问题。我得看看那个有什么不起作用,很奇怪。