vitest-dev / eslint-plugin-vitest

eslint plugin for vitest
MIT License
335 stars 47 forks source link

expect.hasAssertions() / expect.assertions() - Does not work when using expect() bound to current test #567

Open ryanone opened 2 weeks ago

ryanone commented 2 weeks ago

Problem: If you have the prefer-expect-assertions rule enabled, and also have test like the following...

it('my test description, ({ expect }) => {
  const a = 1;
  const b = 2;

  expect(sum(a, b)).toBe(a + b);
})

ESLint fails to detect that expect.assertions() or expect.hasAssertions() is not present. I have an example repo here: https://github.com/ryanone/vitest-eslint-bug

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);
})
ryanone commented 2 weeks ago

cc @austintheriot