But ESLint works properly when using an anonymous function instead of an arrow function...
it('my test description, function ({ expect }) {
// Now ESLint properly complains
const a = 1;
const b = 2;
expect(sum(a, b)).toBe(a + b);
})
Look at src/math.test.ts
There are two test cases. The first one is the one with the expect() method bound to the current context, but does not have a call to expect.assertions() or expect.hasAssertions(). Yet, npm run lint passes. The latter test case uses the expect() method imported from vitest, and has a call to expect.hasAssertions(). If removed, npm run lint will fail.
Problem: If you have the
prefer-expect-assertions
rule enabled, and also have test like the following...ESLint fails to detect that
expect.assertions()
orexpect.hasAssertions()
is not present. I have an example repo here: https://github.com/ryanone/vitest-eslint-bugBut ESLint works properly when using an anonymous function instead of an arrow function...
src/math.test.ts
expect()
method bound to the current context, but does not have a call toexpect.assertions()
orexpect.hasAssertions()
. Yet,npm run lint
passes. The latter test case uses theexpect()
method imported from vitest, and has a call toexpect.hasAssertions()
. If removed,npm run lint
will fail.