我正在使用Jest编写一些规范,并使用ESLint编写样式。
对于我的foo.spec.js
测试,eslint不断抛出以下错误。它似乎认为jest
,beforeEach
,afterEach
,等...没有在该文件中定义。
11:1 error 'beforeEach' is not defined no-undef
12:3 error 'jest' is not defined no-undef
14:13 error 'jest' is not defined no-undef
18:1 error 'afterEach' is not defined no-undef
20:1 error 'describe' is not defined no-undef
21:3 error 'it' is not defined no-undef
25:5 error 'expect' is not defined no-undef
28:5 error 'expect' is not defined no-undef
31:5 error 'expect' is not defined no-undef
34:3 error 'it' is not defined no-undef
38:5 error 'expect' is not defined no-undef
41:5 error 'jest' is not defined no-undef
42:5 error 'expect' is not defined no-undef
43:5 error 'expect' is not defined no-undef
46:3 error 'it' is not defined no-undef
54:5 error 'expect' is not defined no-undef
58:5 error 'jest' is not defined no-undef
我相信这些被jest自动包含,因此不需要在我的spec文件中显式导入它们。实际上,我通过jest.setup.js
文件导入的唯一内容是
import "react-testing-library/cleanup-after-each";
import "jest-dom/extend-expect";
有没有一种方法可以消除这些错误而不必禁用每个文件或内联文件顶部的eslint规则?
谢谢!
请将以下内容添加到您的.eslintrc文件中:
{
"overrides": [
{
"files": [
"**/*.spec.js",
"**/*.spec.jsx"
],
"env": {
"jest": true
}
}
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句