Skip to content

Commit

Permalink
Resolve issue #4459
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmorand-sonarsource committed Mar 26, 2024
1 parent d0fefb2 commit a3ab425
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/jsts/src/rules/S2699/chai.fixture.js
Expand Up @@ -64,3 +64,6 @@ describe('chai test cases', () => {
expect(1).to.equal(2);
}
});

chai.expect(5).to.equal(5); // Compliant: assertion is recognized outside a {describe > it} scope

9 changes: 8 additions & 1 deletion packages/jsts/src/rules/S2699/rule.ts
Expand Up @@ -90,7 +90,14 @@ class TestCaseAssertionVisitor {
return;
}
if (isFunctionCall(node)) {
const functionDef = resolveFunction(this.context, node.callee);
const { callee } = node;

if (callee.name === 'expect') {
this.hasAssertions = true;
return;
}

const functionDef = resolveFunction(this.context, callee);
if (functionDef) {
this.visit(context, functionDef.body, visitedNodes);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/jsts/src/rules/S2699/vitest.fixture.js
Expand Up @@ -19,6 +19,10 @@ describe('vitest test cases', () => {
check();
});

it('recognizes global expect as an assertion', () => {
expect(5).toEqual(5);
});

function check() {
expect(1).toEqual(2);
}
Expand Down

0 comments on commit a3ab425

Please sign in to comment.