Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(no-disabled-tests): use jest function call parser for checking nu…
…mber of args (#1126)
  • Loading branch information
G-Rath committed May 28, 2022
1 parent 81d21c9 commit b67e389
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/rules/__tests__/no-disabled-tests.test.ts
Expand Up @@ -60,6 +60,14 @@ ruleTester.run('no-disabled-tests', rule, {
return {}
}
`,
{
code: dedent`
import { test } from './test-utils';
test('something');
`,
parserOptions: { sourceType: 'module' },
},
],

invalid: [
Expand Down Expand Up @@ -171,5 +179,14 @@ ruleTester.run('no-disabled-tests', rule, {
code: 'describe("contains a call to pending", function () { pending() })',
errors: [{ messageId: 'pendingSuite', column: 54, line: 1 }],
},
{
code: dedent`
import { test } from '@jest/globals';
test('something');
`,
parserOptions: { sourceType: 'module' },
errors: [{ messageId: 'missingFunction', column: 1, line: 3 }],
},
],
});
7 changes: 4 additions & 3 deletions src/rules/no-disabled-tests.ts
Expand Up @@ -30,9 +30,6 @@ export default createRule({
let testDepth = 0;

return {
'CallExpression[callee.name=/^(it|test)$/][arguments.length<2]'(node) {
context.report({ messageId: 'missingFunction', node });
},
CallExpression(node) {
const jestFnCall = parseJestFnCall(node, context.getScope());

Expand All @@ -46,6 +43,10 @@ export default createRule({

if (jestFnCall.type === 'test') {
testDepth++;

if (node.arguments.length < 2) {
context.report({ messageId: 'missingFunction', node });
}
}

if (
Expand Down

0 comments on commit b67e389

Please sign in to comment.