typescript:S2699 (Tests should include assertions) appears unaware of vitest expect(..).not

The following test case, and others similarly using expect(expression).notare flagged with typescript:S2699:

     
it("And we should NOT get contexts[2]", () => {
  expect(result).not.toContain(contexts[2]);
});

The following test case, and others similar, are not flagged:

it("And we should get contexts[1]", () => {
  expect(result).toContain(contexts[1]);
});

I would expect that neither test here would be flagged.

Hi,

Welcome to the community!

Can you provide the context where you’re seeing this? I.E.

 
Thx,
Ann

SonarQube Cloud

Hi,

Thanks! I’ve flagged this for the language experts.

 
Ann

1 Like

Hello @James_Wakefield,

I tried reproducing this, but wasn’t able (see snippet below and PR: JS-987 check vitest expect.not by zglicz · Pull Request #6043 · SonarSource/SonarJS · GitHub)

import { expect } from 'vitest'; // <- this can be removed as well (to use global/jest expect)
describe('vitest test cases', () => {
  it("And we should NOT get contexts[2]", () => {
    expect(result).not.toContain(contexts[2]);
  });
});

Could you provide a more complete example that raises an issue? Specifically, it should include how you import the test libraries.

Kind regards,

Michal

Hi Michal,

We use the vitest functions as globals (configured in our vitest config).

Happy to provide a fuller example privately.

-James