最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jest and ESLint: Expect must have a corresponding matcher call - Stack Overflow

programmeradmin1浏览0评论

I'm getting an ESLint error Expect must have a corresponding matcher call - jest/valid-expect on the first line in this loop where I'm checking for the matching regex (.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)
}))

Not sure what I'm doing wrong since the usage seems to be correct per their documentation. Could this be a bug?

I'm getting an ESLint error Expect must have a corresponding matcher call - jest/valid-expect on the first line in this loop where I'm checking for the matching regex (.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)
}))

Not sure what I'm doing wrong since the usage seems to be correct per their documentation. Could this be a bug?

Share Improve this question edited Jul 31, 2020 at 21:45 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Jul 31, 2020 at 12:12 suuuriamsuuuriam 74714 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The first expect is not asserting anything, and according to the jest/valid-expect rule Ensure expect() is called with a single argument and there is an actual expectation made. this triggers an error. Change to:

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

评论列表(0)

  1. 暂无评论