javascript - Jest 和 ESLint : Expect must have a corresponding matcher call

标签 javascript jestjs eslint

我收到 ESLint 错误 Expect must have a corresponding matcher call - jest/valid-expect在这个循环的第一行,我正在检查匹配的正则表达式( .toMatch )。

const dateRegex = /^([1-9]|1[012])[- \\/.]([1-9]|[12][0-9]|3[01])[- \\/.](19|20)\d\d/

expect(getPerformancePerUserPerDay(input).forEach((item, index) => {
  expect(item['Date']).toMatch(dateRegex)
}))
不确定我做错了什么,因为根据他们的 documentation 的用法似乎是正确的.这可能是一个错误吗?

最佳答案

第一个expect没有断言任何东西,并且根据 jest/valid-expect规则 Ensure expect() is called with a single argument and there is an actual expectation made.这会触发错误。
改成:

getPerformancePerUserPerDay(input).forEach((item, index) => {
  expect(item['Date']).toMatch(dateRegex)
})

关于javascript - Jest 和 ESLint : Expect must have a corresponding matcher call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63191622/

相关文章:

javascript - 如何在 SL4A 上从 python 调用 javascript 方法?

lint - 忽略 eslint 错误 : 'import' and 'export' may only appear at the top level

ecmascript-6 - eslint无法识别Flow Generator类型

javascript - Eslint 禁用行抛出错误

javascript - 如何使用 onclick 更改 div 迭代数组中的字体?

javascript - Web Midi - 列出设备名称

docker - 当我的 Jest 单元测试在 Docker 中失败时,如何获得测试报告?

javascript - 哪个导入与 FontAwesomeIcon、React 和 Jest 一起使用?

javascript - 单击按钮加载新页面(该按钮故意没有形式)

javascript - 对于调用另一个异步函数的异步函数, Jest 测试失败