suuuriam
suuuriam

Reputation: 747

Jest and ESLint: Expect must have a corresponding matcher call

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?

Upvotes: 7

Views: 8551

Answers (1)

nip
nip

Reputation: 1697

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)
})

Upvotes: 7

Related Questions