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.
ganncamp
(G Ann Campbell)
December 1, 2025, 3:08pm
2
Hi,
Welcome to the community!
Can you provide the context where you’re seeing this? I.E.
Are you using
SonarQube Cloud?
SonarQube Server / Community Build - which version?
SonarQube for IDE - which IDE/version?
in connected mode with SonarQube Server / Community Build or SonarQube Cloud?
Thx,
Ann
ganncamp
(G Ann Campbell)
December 3, 2025, 1:47pm
5
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