diff --git a/src/rules/__tests__/max-expects.test.ts b/src/rules/__tests__/max-expects.test.ts index f770dcfde..25750aa25 100644 --- a/src/rules/__tests__/max-expects.test.ts +++ b/src/rules/__tests__/max-expects.test.ts @@ -57,6 +57,37 @@ ruleTester.run('max-expects', rule, { expect(true).toBeDefined(); }); `, + dedent` + test('should pass', async () => { + expect.hasAssertions(); + + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + }); + `, + dedent` + test('should pass', async () => { + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toEqual(expect.any(Boolean)); + }); + `, + dedent` + test('should pass', async () => { + expect.hasAssertions(); + + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toBeDefined(); + expect(true).toEqual(expect.any(Boolean)); + }); + `, dedent` describe('test', () => { test('should pass', () => { diff --git a/src/rules/max-expects.ts b/src/rules/max-expects.ts index 349f21eca..ec221a8b6 100644 --- a/src/rules/max-expects.ts +++ b/src/rules/max-expects.ts @@ -1,5 +1,10 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import { FunctionExpression, createRule, isTypeOfJestFnCall } from './utils'; +import { + FunctionExpression, + createRule, + isTypeOfJestFnCall, + parseJestFnCall, +} from './utils'; export default createRule({ name: __filename, @@ -45,7 +50,12 @@ export default createRule({ FunctionExpression: onFunctionExpressionEnter, ArrowFunctionExpression: onFunctionExpressionEnter, CallExpression(node) { - if (!isTypeOfJestFnCall(node, context, ['expect'])) { + const jestFnCall = parseJestFnCall(node, context); + + if ( + jestFnCall?.type !== 'expect' || + jestFnCall.head.node.parent?.type === AST_NODE_TYPES.MemberExpression + ) { return; }