要解决ESLint规则引发的“应该有1个错误,但实际上没有”错误,您可以采取以下步骤:
打开您项目中的.eslintrc
文件(如果没有,请创建一个)。
在该文件中,找到rules
部分。
在rules
部分中,添加以下规则配置:
{
"rules": {
"jest/expect-expect": ["error", { "assertFunctionNames": ["expect"] }],
"jest/no-conditional-expect": "error",
"jest/no-deprecated-functions": "error",
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "error",
"jest/prefer-expect-assertions": "error",
"jest/prefer-inline-snapshots": "error",
"jest/prefer-spy-on": "error",
"jest/prefer-to-be-null": "error",
"jest/prefer-to-be-undefined": "error",
"jest/prefer-to-contain": "error",
"jest/prefer-to-have-length": "error",
"jest/valid-describe": "error",
"jest/valid-expect": "error",
"jest/valid-expect-in-promise": "error",
"jest/valid-title": "error"
}
}
这样,如果您在断言中使用了contain
,ESLint将会在此处报告错误。您可以相应地修改代码以遵循规则。