Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(no-disabled-tests): use jest function call parser for checking number of args #1126

Merged
merged 1 commit into from May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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